Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.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 将大量列表转换为数据帧中的变量_R_List_Dataframe - Fatal编程技术网

R 将大量列表转换为数据帧中的变量

R 将大量列表转换为数据帧中的变量,r,list,dataframe,R,List,Dataframe,我有几百个长度约4000的列表,我想将它们组合成一个数据帧,每个列表都成为数据帧中的一个变量。如何在新数据框中将列表的名称保留为变量名的同时做到这一点 以下是我到目前为止对前3个列表(formtype、cl和date)的了解 datalist=list() 数据列表[[1]]假设formtype、cl和date是普通向量(不是列表),并且它们位于全局环境中,即工作区中,则: formtype <- cl <- date <- 1:3 # test data Names <

我有几百个长度约4000的列表,我想将它们组合成一个数据帧,每个列表都成为数据帧中的一个变量。如何在新数据框中将列表的名称保留为变量名的同时做到这一点

以下是我到目前为止对前3个列表(formtype、cl和date)的了解

datalist=list()

数据列表[[1]]假设
formtype
cl
date
是普通向量(不是列表),并且它们位于全局环境中,即工作区中,则:

formtype <- cl <- date <- 1:3  # test data
Names <- c("formtype", "cl", "date")
as.data.frame(mget(Names, .GlobalEnv))
如果
formtype
cl
date
确实是如下所示的列表,则
取消列出每个:

formtype <- cl <- data <- as.list(1:3) # test data
Names <- c("formtype", "cl", "date")
as.data.frame(lapply(mget(Names, .GlobalEnv), unlist))

formtype
as.data.frame(datalist)
?我在尝试时遇到了以下错误:函数中的错误(…,row.names=NULL,check.rows=FALSE,check.names=TRUE,:参数表示行数不同:12311101227如果列表中的项目长度不同,则不能将它们组合到单个数据帧的列中。
  formtype cl date
1        1  1    1
2        2  2    2
3        3  3    3
formtype <- cl <- data <- as.list(1:3) # test data
Names <- c("formtype", "cl", "date")
as.data.frame(lapply(mget(Names, .GlobalEnv), unlist))