[問題] incorrect number of subscripts

看板R_Language作者時間6年前 (2019/05/20 03:02), 6年前編輯推噓0(004)
留言4則, 3人參與, 6年前最新討論串1/1
[問題類型]: [updated] 已經解決了 謝謝大家 我就是直接把第121個欄位填進去CT.raw[i,121] 因為最後一個欄位是120 所以我就把新的欄位加到最後方 就可以了 但是function還是沒有辦法 我之前試著寫一個function 但是我用Data=CT.raw 就沒反應 用CT.raw=Data也不行 但上述用loop跑就可以 為了完成專案 就先用loop去做了 另外網址我是沒有被要求登入耶@@ 我換成google drive試試看好了 謝謝所有回覆的大大 請把以下不需要的部份刪除 意見調查(我對R 有個很棒的想法,想問問大家的意見) 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 入門 [問題敘述]: 請簡略描述你所要做的事情,或是這個程式的目的 目前在做的專案需要根據sample中不同的size去配置合適的random數 我寫出loop了 但只要在loop外測試都沒問題 但放進loop中 就持續收到error: incorrect number of subscrits on matrix 但我已經確認資料檔案都是data frame 已感到黔驢技窮 還請大家幫忙 資料檔案和code都不複雜 但不知道為何debug不出來 資料檔案在這 https://reurl.cc/Ynrvl [程式範例]: CT.raw <- read.csv(file = "CT_raw.csv", header = TRUE, as.is = FALSE) x=seq(from=2, to=1730, length=1729) ##只要從row 2到row 1730## set.seed(123) for (i in x){ #for j = 11 to 91 if (is.na(CT.raw[i,90])==FALSE){ index = sample(1:80, 35, replace=FALSE) index <- as.numeric(index) CT.raw <- as.data.frame(CT.raw) CT.raw$average[i,]= mean(as.numeric(unlist(as.data.frame(CT.raw[i,11:90])[,c(index)])), trim = 0, na.rm = TRUE) }else if (is.na(CT.raw[i,60])==FALSE & is.na(CT.raw[i,61])==TRUE){ index = sample(1:50, 25, replace=FALSE) index <- as.numeric(index) CT.raw$average[i,]= mean(as.numeric(unlist(as.data.frame(CT.raw[i,11:90])[,c(index)])), trim=0, na.rm=TRUE) } else if (is.na(CT.raw[i,42])==FALSE & is.na(CT.raw[i,43])==TRUE){ index = sample(1:32, 20, replace=FALSE) index <- as.numeric(index) CT.raw$average[i,]= mean(as.numeric(unlist(as.data.frame(CT.raw[i,11:90])[,c(index)])), trim=0, na.rm=TRUE) } else if (is.na(CT.raw[i,30])==FALSE & is.na(CT.raw[i,31])==TRUE){ index = sample(1:20, 15, replace=FALSE) index <- as.numeric(index) CT.raw$average[i,]= mean(as.numeric(unlist(as.data.frame(CT.raw[i,11:90])[,c(index)])), trim=0, na.rm=TRUE) } } [環境敘述]: R version 3.5.3 (2019-03-11) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS High Sierra 10.13.6 Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_3.5.3 tools_3.5.3 yaml_2.2.0 [關鍵字]: 選擇性,也許未來有用 -- -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 129.21.69.248 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1558292555.A.D51.html ※ 編輯: AmigoSafin (129.21.69.248), 05/20/2019 03:03:03

05/20 08:54, 6年前 , 1F
網址要求登入...
05/20 08:54, 1F

05/20 13:36, 6年前 , 2F
可以利用map跟nest的組合處理不同群體樣本大小的抽
05/20 13:36, 2F

05/20 13:37, 6年前 , 3F
樣。請參: https://reurl.cc/6enYZ
05/20 13:37, 3F

05/21 07:16, 6年前 , 4F
真的嗎?真是抱歉 我已找出解答 謝謝A大!!
05/21 07:16, 4F
※ 編輯: AmigoSafin (68.180.87.229), 05/21/2019 07:30:39
文章代碼(AID): #1SuQXBrH (R_Language)
文章代碼(AID): #1SuQXBrH (R_Language)