The R language doesn't allow vectors to be variables. Why it is missing the feature? it would be nice my data frame with following features have something like this:
X1 X2
1. [1,2,3] [2,3,4] <br>
2. .... ....
I tried df <- as.data.frame(c(1,2,3),c(1,2,3))
but keep getting 3 rows created with numeric type instead I want a single row with vector type
答案 0 :(得分:0)
Use an array:
array(rbind(1:3, 2:4), dim = c(1, 2, 3))
#, , 1
#
# [,1] [,2]
#[1,] 1 2
#
#, , 2
#
# [,1] [,2]
#[1,] 2 3
#
#, , 3
#
# [,1] [,2]
#[1,] 3 4
答案 1 :(得分:0)
R不允许使用行数据类型,您可以使用列数据类型。每列可以是单独的数据类型向量。你不是在想'R'的方式。正如你所说的那样,这就是R的优势。你可以使用前一个答案中建议的数组,如果你真的想要遵循你的想法。或者只是试着看看你如何在'R'中做你想做的事。而不是试图将你已知的语言强加给R。