"when used with numbers and tapply" 引起的错误如何解决?R,包安排

How to fix the error caused by" when used with numbers and tapply? R, package arrangements

我在 Windows 10 中使用包安排 v1.1.5 和 R v3.5.3。 而且我想我发现了一个奇怪的错误或者我做错了什么。

这是有效的

library(arrangements)
myDF <- data.frame(A=c("a","b","c"), B=c(2000,2000,2002))
tapply(myDF$A,myDF$B, permutations)

$`2000`
     [,1] [,2]
[1,] a    b   
[2,] b    a   
Levels: a b c

$`2002`
     [,1]
[1,] c   
Levels: a b c

但这不起作用:

library(arrangements)
myDF <- data.frame(A=c(200,200,200), B=c(0,0,2))
tapply(myDF$A,myDF$B, permutations)

Error in FUN(X[[i]], ...) : too many results

我做错了什么?
我只想生成由组 B 定义的 A 元素的排列。
结果应该与前面的示例类似,但使用数字而不是字母。

查看 ?permutations 上的文档。请注意,第一个参数描述为

x -- an integer or a vector, will be treated as n if integer; otherwise, will be treated as v

因此,如果您传入数字或因数,函数的行为会有所不同。如果你想像第一个例子那样从中提取这些值,你可以直接将值传递给 v= 参数。

tapply(myDF$A, myDF$B, function(x) permutations(v=x))