使用通配符Rbind数据帧

使用通配符Rbind数据帧,r,wildcard,rbind,R,Wildcard,Rbind,假设我有三个数据帧,分别称为A1 pre、B3 pos、B4 pre,我想合并这些数据帧。这些列具有相同的名称,因此我可以使用rbind newdf <- rbind(A1-pre, B3-pos, B4-pre) #this would work newdf您可以使用get()和ls(): 'A1-pre'您真的用名称中的-命名了数据帧?研究使用ls(),do.call(),和get()。或do.call(rbind,lapply(ls(pattern=“-pre”),get))等等

假设我有三个数据帧,分别称为A1 pre、B3 pos、B4 pre,我想合并这些数据帧。这些列具有相同的名称,因此我可以使用rbind

newdf <- rbind(A1-pre, B3-pos, B4-pre)  #this would work

newdf您可以使用
get()
ls()


'A1-pre'您真的用名称中的
-
命名了
数据帧?研究使用
ls()
do.call()
,和
get()
。或
do.call(rbind,lapply(ls(pattern=“-pre”),get))
等等,正如我在评论中提到的那样。
newdf <- rbind(grep(-)) #but this does not work
'A1-pre' <- matrix(rnorm(100), 5) 
'B3-pos' <- matrix(rnorm(100), 5)
'B4-pre' <- matrix(rnorm(100), 5)
'C5-not' <- matrix(rnorm(100), 5)

names <- grep('pre|pos$', ls(), value=T)

newDF <- mapply(get, grep('pre|pos$', ls(), value=T))