假设我有一个数据框列表。每个数据框都有这样的列:
lists$a
company, x, y ,z
lists$b
company, x, y, z
lists$c
company, x, y, z
关于我的意思的任何想法将其更改为:
new.list$company
a,x,y,z
b,x,y,z
c,x,y,z
new.list$company2
a,x,y,z
b,x,y,z
c,x,y,z
我一直在使用:
new.list[[company]] <- ldply(lists, subset, company=company.name)
但这一次只能做一个。有没有更短的方法?
最佳答案
布兰登,
您可以使用 |
中的 cast
参数来创建列表。使用来自@Wojciech 的 data.frame:
require(reshape)
dat.m <- melt(dat_1, "company")
cast(dat.m, L1 ~ variable | company)
关于重组 data.frames 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5906716/