通过查看以下代码stack
:
> getS3method('stack', 'default')
function (x, ...)
{
x <- as.list(x)
keep <- unlist(lapply(x, is.vector))
if (!sum(keep))
stop("at least one vector element is required")
if (!all(keep))
warning("non-vector elements will be ignored")
x <- x[keep]
data.frame(values = unlist(unname(x)), ind = factor(rep.int(names(x),
lapply(x, length))), stringsAsFactors = FALSE)
}
如您所见,...
参数未传递给data.frame
创建。您可以通过创建 say 来修改此函数,stack2
如下所示:
stack2 <- function (x, ...)
{
x <- as.list(x)
keep <- unlist(lapply(x, is.vector))
if (!sum(keep))
stop("at least one vector element is required")
if (!all(keep))
warning("non-vector elements will be ignored")
x <- x[keep]
data.frame(values = unlist(unname(x)), ind = factor(rep.int(names(x),
lapply(x, length))), stringsAsFactors = FALSE, ...) # note the ... here
}
# after copy/paste of stack2 function
> stack2(a1, check.names = FALSE)
values ind
1 1 a
2 2 a
3 3 a
4 4 a
5 5 a
6 6 a
7 7 a
8 8 a
9 9 a
10 10 a
11 11 b
12 12 b
13 13 b
14 14 b
15 15 b
16 16 b
17 17 b
18 18 b
19 19 b
20 20 b
21 21 a
22 22 a
23 23 a
24 24 a
25 25 a
26 26 a
27 27 a
28 28 a
29 29 a
30 30 a
注意:不要将stringsAsFactors = .
参数传递给这个stack2
函数,因为它已经传递了。可能这就是为什么他们不通过...
论点?