r - 将文件读入 R,然后对它们应用相同的函数并返回结果文件
问题描述
我有 100 多个具有相同列的文件。我使用以下代码将它们读入 R:
# packages
require(data.table)
# set wd
setwd("PathToYourFolder")
# import files
files = list.files(pattern="*.txt.results")
我想将以下功能应用于所有这些文件:
fdr <- p.adjust (file$col4, method = "fdr", n = length(file$col4))
我尝试了以下方法:
lapply(files, p.adjust (files$col4, method = "fdr", n = length (files$col4)))
你能告诉我怎么做吗?
解决方案
好吧,你很接近。
your.p.values <- lapply(files, function(file) {
dat <- read.csv( file )
p.adjust (dat$col4, method = "fdr", n = length (dat$col4)))
})
## add the filenames to them to keep better order of things:
names(your.p.values) <- files
包中有一个函数purrr
可以为您将文件的名称添加到列表中,为您节省一步并稍微简化代码,但上述解决方案应该可以解决这个问题。
推荐阅读
- rest - spring restfull service request and response as Text/plan
- react-native - 如何修复与哨兵相关的纱线错误:ENOENT:没有这样的文件或目录,scandir '.../src/native/node_modules/@sentry'
- c# - 内存中asp.net核心中的会话
- excel - How can I set a string variable as a color in VBA?
- javascript - 如何知道 javascript 是否应该位于 html 的底部或底部?
- python - Elasticsearch Python 将扫描器的结果传递给批量写入器
- .net-core - dotnet core azure web app - okta 应用程序网关
- java - 是否可以要求抽象类的子类覆盖超类的继承方法?
- azure - 无法调整虚拟机大小
- sql-server - 根据 CASE/IIF 标准创建具有新列连接的查询