R列出具有多个条件的文件 [英] R list files with multiple conditions

查看:91
本文介绍了R列出具有多个条件的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想列出目录中满足某些条件(日期和货币)的所有文件.因此,只有一种情况,list.files中的参数pattern可以很好地工作:

I want to list all files in a directory that met certain conditions (date and currency). So with only one condition the argument pattern in list.files works well:

    file.ls <- list.files(path='~/DATA/PiP/Curvas/',pattern='20130801')

对于多种情况,我都尝试过:

For multiple conditions I've tried:

    file.ls <- list.files(path='~/DATA/PiP/Curvas/',pattern=c('20130801','USD'))

但结果与第一个相同.在list.filespattern自变量中是否有多个条件?

But had the same result as the first one. Is there a way to have multiple criteria in pattern argument of list.files?

推荐答案

 Filter(function(x) grepl("USD", x), file.ls)

或者,您可以为pattern构造一个正则表达式,使其仅匹配包含两个字符串的文件名,但这是向导的游戏.

alternatively, you could construct a regular expression for pattern that only matches filenames containing both strings, but that's a wizard's game.

这篇关于R列出具有多个条件的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆