看板 R_Language 關於我們 聯絡資訊
後來想到更快的方法 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 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.164.192.51 ※ 文章網址: http://www.ptt.cc/bbs/R_Language/M.1406659651.A.070.html ※ 編輯: celestialgod (218.164.78.247), 08/03/2014 19:44:37