我将工作目录中的所有文本文件读入列表,并删除了一些列
all.files <- list.files(pattern = ".*.txt")
data.list <- lapply(all.files, function(x)read.table(x, sep="\t"))
names(data.list) <- all.files
data.list <- lapply(data.list, function(x) x[,1:3])
我最终得到了“2的清单”
> str(data.list)
List of 2
$ 001.txt:'data.frame': 71330 obs. of 3 variables:
..$ V1: Factor w/ 71321 levels
..$ V2: Factor w/ 1382 levels
..$ V3: num [1:71330] 89.1 99.5 98.8 99.4 99.5 ...
$ 002.txt:'data.frame': 98532 obs. of 3 variables
..$ V1: Factor w/ 98517 levels
..$ V2: Factor w/ 1348 levels
..$ V3: num [1:98532] 99.5 99 99.5 98.4 100 ...
我想根据
重命名V1,V2,V3new.names<-c("query", "sbjct", "ident")
拉普利怎么可能?
答案 0 :(得分:5)
您可以尝试setNames
data.list <- lapply(data.list, setNames, new.names)