Re: [问题] 多个档案合并 取联集

楼主: celestialgod (天)   2014-07-30 02:47:28
后来想到更快的方法
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

Links booklink

Contact Us: admin [ a t ] ucptt.com