R_Language 板


LINE

※ 引述《aa955260 (aa955260)》之铭言: : [问题类型]: : 程式谘询(我想用R 做某件事情,但是我不知道要怎麽用R 写出来) : [软体熟悉度]: : 入门(写过其他程式,只是对语法不熟悉) : [问题叙述]: : 各位大大好,我的资料集内有多个人(sub.list),每个人下面有3种不同状态(stat.list) : ,每种状态下有3种不同的状况(level.list),目前我是用for-loop来分别读取2维的 : data.frame(A, B, C),我想做的是用Scal.list将3种不同level.list的资料与名称包起 : 来,再用All.list把3种不同stat.list的资料与名称包起来,做成1个大的All.list。以 : 下为错误范例,请问我该怎麽修改会比较好呢?或是有没有其他更好的写法呢? : 感谢 : [程式范例]: : sub.list <- list("001", "002", "003") : stat.list <- list("High", "Low", "None") : level.list <- list("Light", "Moderate", "Vigorous") : Scal.list <- list() : All.list <- list() : for(i in 1:length(sub.list)){ : for(j in 1:length(stat.list)){ : A_path <- paste0(data.path, sub.list[i], "\\", stat.list[j] : ,"\\", level.list[1], ".csv") : A <- fread(A_path, header = T) : B_path <- paste0(data.path, sub.list[i], "\\", stat.list[j] : , "\\", level.list[2], ".csv") : B <- fread(B_path , header = T) : C_path <- paste0(data.path, sub.list[i], "\\", stat.list[j] : , "\\", level.list[3], ".csv") : C <- fread(C_path, header = T) : t.list <- list() : t.list <- list(A, B, C) : names(t.list)[1] <- level.list[1] : names(t.list)[2] <- level.list[2] : names(t.list)[3] <- level.list[3] : Scal.list[[length(Scal.list)+1]] <- t.list : } : All.list[[length(All.list)+1]] <- Scal.list : } : [环境叙述]: : R version 3.3.2 (2016-10-31) : Platform: x86_64-w64-mingw32/x64 (64-bit) : Running under: Windows >= 8 x64 (build 9200) : locale: : [1] LC_COLLATE=Chinese (Traditional)_Taiwan.950 LC_CTYPE=Chinese : (Traditional)_Taiwan.950 : [3] LC_MONETARY=Chinese (Traditional)_Taiwan.950 LC_NUMERIC=C : [5] LC_TIME=Chinese (Traditional)_Taiwan.950 : attached base packages: : [1] stats graphics grDevices utils datasets methods base : loaded via a namespace (and not attached): : [1] tools_3.3.2 : [关键字]: : : 多层list、多层回圈读档 : library(data.table) subVec <- c("001", "002", "003") statVec <- c("High", "Low", "None") levelVec <- c("Light", "Moderate", "Vigorous") # data.frame做法 DF <- expand.grid(sub = subVec, stat = statVec, level = levelVec) DF <- transform(DF, path = paste0(dataPath, "/", sub, "/", stat, "/", level, ".csv")) # data.table做法 DT <- CJ(sub = subVec, stat = statVec, level = levelVec) DT[ , path := paste0(dataPath, "/", sub, "/", stat, "/", level, ".csv")] # 读档 sapply(DT$path, fread, header = TRUE) -- R资料整理套件系列文: magrittr #1LhSWhpH (R_Language) https://goo.gl/72l1m9 data.table #1LhW7Tvj (R_Language) https://goo.gl/PZa6Ue dplyr(上.下) #1LhpJCfB,#1Lhw8b-s (R_Language) https://goo.gl/I5xX9b tidyr #1Liqls1R (R_Language) https://goo.gl/i7yzAz pipeR #1NXESRm5 (R_Language) https://goo.gl/zRUISx --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.38.133.116
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1484217423.A.5B8.html







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Gossiping站内搜寻

TOP