[英]convert list type to data frame type in R, data.frame and as.data.frame does not wok
I have created A with command data.frame in R, but the data type of A is "list", and I have already tried to convert A to data frame with as.data.frame but it does work, anyone else has same experience? 我已经在R中使用命令data.frame创建了A,但是A的数据类型是“列表”,并且我已经尝试过使用as.data.frame将A转换为数据帧,但是它确实有效,其他任何人都有相同的经验? the code are below:
代码如下:
A <- data.frame(rep(1,5), row.names=c("A","B","C","D","E"), check.rows = FALSE, check.names = FALSE)
mode(A)
A1 <- as.data.frame(A)
mode(A1)
As data.frame
is a list
with length of each list
element ( column
) same, the mode
returns a list
. 由于
data.frame
是一个list
,每个list
元素( column
)的长度相同,因此该mode
返回一个list
。 We can use 我们可以用
class(A)
#[1] "data.frame"
and 和
is.data.frame(A)
#[1] TRUE
from @RHertel's commments 来自@RHertel的评论
is.list(A)
#[1] TRUE
or 要么
str(A)
#'data.frame': 5 obs. of 1 variable:
# $ rep(1, 5): num 1 1 1 1 1
dput(A)
to confirm that a data.frame
is also a list
. 确认
data.frame
也是一个list
。
But, list
also can have equal length and not a data.frame
但是,
list
也可以具有相等的长度,而不是data.frame
l1 <- as.list(1:5)
mode(l1)
#[1] "list"
class(l1)
#[1] "list"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.