【发布时间】:2017-08-26 16:25:09
【问题描述】:
我需要保存 csv 文件列表,并从每个数据帧的特定列(第二列)的第 13 行中提取值。
这是我的尝试:
temp <- list.files(FILEPATH, pattern="*\\.csv$", full.names = TRUE)
for (i in 1:length(temp)){
assign(temp[i], read.csv(temp[i], header=TRUE, ski[=13, na.strings=c("", "NA")))
subset(temp[i], select=2) #extract the second column of the dataframe
temp[i] <- na.omit(temp[i])
但是,这不起作用。一方面,我认为这是因为 read.csv 命令的 skip 参数,因为它显然忽略了标题。另一方面,如果不使用skip,则会弹出如下错误:
subset.default(temp[i], select = 2) 中的错误:参数“子集”为 缺失,没有默认值
当我在subset 命令中插入参数subset=TRUE 时,它不会给出任何错误,但不会执行提取。
任何可能的解决方案?
【问题讨论】:
标签: r for-loop subset read.csv