后来想到更快的方法
library(data.table)
working_path = "the directory of your file"
setwd(working_path)
file_list = dir()[grepl("txt", dir())]
dat_list = lapply(1:length(file_list), function(l){
dat = fread(l, header = TRUE)
dat = data.table(cate = row.names(dat), dat)
dat
})
dat2 = rbindlist(dat_list)
output_table = dcast.data.table(dat2, name ~ day)
# name day1 day2 day3
# 1: A 23 77 NA
# 2: B 45 NA 11
# 3: C NA 11 NA
# 4: D 100 35 44
# 5: E NA NA 55