2015-11-15 17 views
0

我在一个实验室工作,其中我们每天收集超过100个.csv文件的记录时间锁定事件。我们需要从每个文件中提取具体的时间点输出,并且手动提取这些数字的效率不高。在R stuidio中从多个csv文件中提取和编译特定数据行

我想知道任何人有想法如何编码R脚本,将提取和编译这些时间点?我一直在研究mcsv_r()函数;但是我需要知道哪些文件的时间点出来了,我不确定该功能是否可用。 30

下面是这也许可以解释什么,我想比我能做到更好的图像,这是从一个单一的文件(文件#1):

The numbers in the first column that correspond to 253, 254, and 251 in the third column is the data I'd like to extract

我是一个新手至少在编码方面。非常感谢你的帮助!

+0

不要将您的数据作为图像发布,请学习如何给出[可重现的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) – Jaap

回答

1

尝试这样:

# get a list of the csv files in the directory 
files = list.files(path = ".", pattern = "csv") 

n = data.frame() 
for (file in files) { 
    csv = read.csv(file) 
    # X3 is the default third column name -- you might have to change that 
    data = csv[csv$X3 %in% c(251, 253, 254), ] 
    data$file = file # add a new column with the filename 
    n = rbind(n, data) 
} 

write.csv(n, file = "compiled_data.csv") 

您的图片显示在第一列的一些空白领域。如果你想排除这些行,这将不得不稍微编辑。

相关问题