Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中将列表类型转换为数据帧类型,data.frame和as.data.frame不起作用_R_List_Dataframe - Fatal编程技术网

在R中将列表类型转换为数据帧类型,data.frame和as.data.frame不起作用

在R中将列表类型转换为数据帧类型,data.frame和as.data.frame不起作用,r,list,dataframe,R,List,Dataframe,我在R中使用命令data.frame创建了一个,但A的数据类型是“list”,我已经尝试使用as.data.frame将A转换为数据帧,但它确实有效,其他人有相同的经验吗?代码如下: 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) A作为数据。fram

我在R中使用命令data.frame创建了一个,但A的数据类型是“list”,我已经尝试使用as.data.frame将A转换为数据帧,但它确实有效,其他人有相同的经验吗?代码如下:

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)

A作为
数据。frame
是一个
列表
,每个
列表
元素(
)的长度相同,
模式
返回一个
列表
。我们可以使用

class(A)
#[1] "data.frame"

来自@RHertel的评论

is.list(A)  
#[1] TRUE

确认
数据框
也是
列表

但是,
列表
也可以具有相同的长度,而不是
数据帧

l1 <- as.list(1:5)
mode(l1)
#[1] "list"
class(l1)
#[1] "list"

l1a
数据。帧
是一个
列表
。检查
is.data.frame(A)#[1]TRUE
str(A)
#'data.frame':   5 obs. of  1 variable:
# $ rep(1, 5): num  1 1 1 1 1

dput(A)
l1 <- as.list(1:5)
mode(l1)
#[1] "list"
class(l1)
#[1] "list"