【发布时间】:2011-10-09 05:31:42
【问题描述】:
您好,我想比较两个目录中的文件:
allfilenames <- list.files(path="../XYZ")
names1=allfilenames[grep("XYZ_*",allfilenames)]
numfiles <- length(names1)
allfilenames2 <- list.files(path="../ABC")
names2=allfilenames2[grep("ABC_*",allfilenames2)]
numfiles <- length(names2)
for(i in names1){
if(exists(i in names2){...}###?????
else...
}
is存在函数不对!是否有其他功能可以查看来自一个导演的文件是否存在于另一个导演中?
【问题讨论】:
-
在索引中,最好使用
grepl而不是` grep. When there are no matches,grep` 返回一个空的数字向量,这会导致索引返回所有内容(而不是什么都没有)。
标签: function r loops statistics