我無法圍繞?stack的文檔,以及爲什麼它不工作。試想一下:理解Stack()的工作原理
> set.seed(1)
> x1 = sample(c(letters[1:5], NA), size=10, replace=TRUE)
> x2 = sample(c(letters[1:5], NA), size=10, replace=TRUE)
> is.vector(x1)
[1] TRUE
> rbind(x1, x2)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
x1 "b" "c" "d" NA "b" NA NA "d" "d" "a"
x2 "b" "b" "e" "c" "e" "c" "e" NA "c" "e"
> stack(x1, x2)
Error in rep.int(names(x), lapply(x, length)) : invalid 'times' value
> stack(list(x1, x2))
Error in rep.int(names(x), lapply(x, length)) : invalid 'times' value
> df = data.frame(x1=x1, x2=x2)
> stack(df)
Error in stack.data.frame(df) : no vector columns were selected
下面是我想:
values ind
"b" "x1"
"c" "x1"
"d" "x1"
NA "x1"
... etc.
而不僅僅是一個列表,而是一個_named_列表(或一個data.frame)。 –
@JoshuaUlrich我認爲文檔應該更清楚一些。 – joran
我同意,但有人會說,只是使用plyr,所以這是一個有爭議的問題。 :) –