Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我的工作区中有一堆变量。我想将它们的一个子集分配给一个新变量,这样我就可以轻松地在这个子集上运行函数:
工作区:
... group10 group40 location40 test
期望的任务:
groupList <- list(group10,group40, ...)
预期的正则表达式:
^group[0-9]+
有任何想法吗?
ls接受一个pattern论点:
ls
pattern
group10 <- group40 <- location40 <- test <- NA mysub <- ls(pattern="^group[0-9]+") mysub #[1] "group10" "group40"
您可以使用lapply循环变量名称get及其值的列表
lapply
get
groupList <- lapply(mysub, get)
或者,在一行中
groupList <- lapply(ls(pattern="^group[0-9]+"), get)