【发布时间】:2017-10-30 18:26:11
【问题描述】:
我有以下代码:
file_list <- list.files(path=folder, pattern="*.txt") ##creates list of all txt. files in folder
file_list
o<- file_list[order(as.numeric(gsub(".+_(\\d+)\\.txt$", "\\1", file_list)))]## orders list in numerical order by ending
r <- sapply(o, FUN = function(x){
df = read.table(x, skip=1) ##x is the file name from list
mean(df$V4)
}) ###takes mean of selected column from entire list and produces below output
这提供了以下输出:
172010_001_120VC_0.1_1100.txt 3.817672e-07
172010_001_120VC_0.1_1080.txt 3.893099e-07
172010_001_120VC_0.1_1090.txt 4.386539e-07
如何将输出转换为向量/数据框 x= txt 文件标签的最后一位数字(1100、1080、1090 等,y = 数值(3.817672e-07、3.893099e-07 , 4.386539e-07 等)
【问题讨论】: