Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.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 - Fatal编程技术网

R 从一个列表创建两个列表

R 从一个列表创建两个列表,r,list,R,List,我使用lappy(list,table)获取列表中元素的频率。有没有办法将此列表分成两个单独的列表 l1 <- c("1030","110"....) #Factors l2 <- c(2,1,...) #Numbers $`1` 1030 110 130 15 164 20 212 227 27 282 289 293 30 303 317 318 344 404 41 462 471 2 1 12 11

我使用
lappy(list,table)
获取列表中元素的频率。有没有办法将此列表分成两个单独的列表

l1 <- c("1030","110"....) #Factors
l2 <- c(2,1,...) #Numbers

$`1`

1030  110  130   15  164   20  212  227   27  282  289  293   30  303  317  318  344  404   41  462  471 
   2    1   12   11    4    1    4    1    5    1    5    2    1    4    1    5    1    1    2    2    3 
 476   48  480  486    5  502   52  521  522  526   56  577   58  590   60  607  624  634  645  659   66 
   2   20    1    4    5    1    1    2    5    2    1    1    1    1    6    2    1    1    1    2    3 
 664  674  686   69  737  803  810  815   85   86   87  885   89  894   91  913  917   96  963  970   98 
   1    1    4    2    1    1    1    1    6    1    3    2    1    1    1    2    1    5    1    1    1 
  99 
   4 

l1使用
names
获取表的名称(即l1),使用
unname
从未列出的向量中删除名称属性(即l2)

#一些数据
s
# some data
s <- list(sample(1:10, 100, T), sample(1:10, 100, T))
l <- lapply(s, table)

# if you want to combine all elements of list together
l1 <- names(unlist(l))
l2 <- unname(unlist(l))

# you want to maintain the list structure
lapply(l, function(i) list(l1=names(i), l2=unname(i)))