开发者

How can I use pattern to combine data frames using a wildcard?

开发者 https://www.devze.com 2023-01-08 09:57 出处:网络
A series of functions generate varying number of data frames (minimum of 1 and a max of 11). I\'d like to combine them using rbind. If I knew the names, I c开发者_运维百科ould easily just rbind(d1,d2.

A series of functions generate varying number of data frames (minimum of 1 and a max of 11). I'd like to combine them using rbind. If I knew the names, I c开发者_运维百科ould easily just rbind(d1,d2...) but can't do that since I have to combine a different number of data frames each time.

So lags=rbind(pattern("lags_2_Y*")) didn't work.

I can get the list of the generated lag names into a vector like so: lag_names=ls(pattern="lags_2_Y*")

If I do: lags=llply(lag_names,rbind), I just get a list with the lag names. I want to rbind the contents of those data frames.

Ideas?


try

library(plyr)
lags = ldply(lag_names, get)

Edit:

If you give lag_names names, ldply() will add an id column

names(lag_names) <- lag_names

lags = ldply(lag_names, get)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号