【发布时间】:2021-06-08 13:25:14
【问题描述】:
[已删除][已删除][已删除][已删除]
【问题讨论】:
[已删除][已删除][已删除][已删除]
【问题讨论】:
这是读取所有文件并对其进行处理的一种方法。未经测试的代码,因为您没有给我们任何工作。
# Get a list of CSV files. Use the path argument to point to a folder
# other than the current working directory
files <- list.files(pattern=".+\\.csv")
# For each file, work your magic
# lapply runs the function defined in the second argument on each
# value of the first argument
everything <- lapply(
files,
function(f) {
values <- read.csv(f, header=FALSE)
apply(values, 1, function(x) length(which(x==3)))
}
)
# And returns the results in a list. Each element consists of
# the results from one function call.
# Make sure you can access the elements of the list by filename
names(everything) <- files
# The return value is a list. Access all of it with
everything
# Or a single element with
everything[["values04.csv"]]
【讨论】: