作者AmigoSafin ()
看板R_Language
标题[问题] incorrect number of subscripts
时间Mon May 20 03:02:32 2019
[问题类型]:
[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://webptt.com/cn.aspx?n=bbs/R_Language/M.1558292555.A.D51.html
※ 编辑: AmigoSafin (129.21.69.248), 05/20/2019 03:03:03
1F:→ andrew43: 网址要求登入... 05/20 08:54
2F:→ bboybighead2: 可以利用map跟nest的组合处理不同群体样本大小的抽 05/20 13:36
4F:→ AmigoSafin: 真的吗?真是抱歉 我已找出解答 谢谢A大!! 05/21 07:16
※ 编辑: AmigoSafin (68.180.87.229), 05/21/2019 07:30:39