我有三个矩阵,我需要3个嵌套for循环才能进行我需要的计算。我的coeff矩阵看起来像:
lm.obj.coefficients lm.obj.coefficients.1 lm.obj.coefficients.2 lm.obj.coefficients.3 lm.obj.coefficients.4 lm.obj.coefficients.5 lm.obj.coefficien
4.552 0.61061 -0.06482 -0.22394 -0.08651 0.00306 -0.02061 -0.03066 2.35086 5.86607 0.92518 -8.1581 -0.21651 5.43852 -0.23804 -0.24025 -0.52292 -0.2
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
0.15725 0.13373 0.03761 -0.05429 0.0286 0.06517 0.05556 0.0515 0.01382 -0.06581 0.27052 1.06467 -0.01288 0.59487 0.02043 0.02361 -0.03473 0.01682
Matrix残差看起来像:
lm.obj.residuals lm.obj.residuals.1 lm.obj.residuals.2 lm.obj.residuals.3 lm.obj.residuals.4 lm.obj.residuals.5 lm.obj.residuals.6 lm.obj.residuals
0.00231 -1.89973 -0.0127 2.06897 -0.01311 -0.01215 -0.01229 -0.01237 -0.30846 -0.10754 0.06169 -0.18151 -0.0109 0.24604 -0.08252 -0.08839 0.02824 0
0.07514 0.18595 0.02237 -2.36732 0.02135 0.02571 0.02452 0.02403 0.06232 -0.05302 -0.0302 -0.09606 0.00519 -0.61982 -0.01513 -0.01797 0.01261 -0.00
和mod:
row.names (Intercept) as.factor(tissue3)Gastrointestinal as.factor(tissue3)Hematopoietic as.factor(tissue3)Musculo_endo as.factor(Submission_
Adipose_Derived_1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 -0.0242845514406503 -0.28919947646494 0.164493834188179 -0.189891956939011 -0.01075313372
Adipose_Derived_92 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 -0.0387879882628922 -0.266146134934971 0.125790966152757 -0.253593603953948 0.00062908003
Adipose_Derived_93 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0.0856909184783238 -0.267523926775753 0.0601909297700556 -0.418856504832572 -0.0421275186
我的代码是:
coeff<-read.table("lm_coeff_rounded.txt",header=T,colClasses="numeric",nrows=31,comment.char="")
resid<-read.table("lm_resid_rounded.txt",header=T,colClasses="numeric",nrows=103,comment.char="")
mod<-read.table("mod.our",header=T)
coeff<-as.matrix(coeff)
resid<-as.matrix(resid)
mod<-as.matrix(mod)
coeff<-coeff[-2,]
mod<-mod[,-1]
cov.pred<-matrix(0,102,10)
for (j in 1:10){
for (i in 1:102){
for(z in 5:29){
cov.pred[i,j]<-coeff[1,j] + resid[i,j] + (coeff[z,j]*mod[i,z])
}
}
}
write.table(cov.pred,"covariate_predicted_folds.txt",row.names=F,quote=F)
我收到了这些错误:
/ bin / sh:BASH_FUNC_module():第0行:意外标记)'
/bin/sh: BASH_FUNC_module(): line 0:
附近的语法错误BASH_FUNC_module()(){eval /usr/bin/modulecmd bash $*
'
/ bin / sh:错误导入`BASH_FUNC_module'的函数定义
coeff [z,j] * mod [i,z]中的错误:
二元运算符的非数字参数
有谁知道问题是什么?
答案 0 :(得分:0)
您可以查看错误消息:
Error in coeff[z, j] * mod[i, z] : non-numeric argument to binary operator
这表示您正在使用非数字参数计算产品。
因此表mod具有非数字元素。如果您运行代码直到错误弹出并且一切都停止,您应该能够通过键入mod [i,z]来获得该值。
(我不确定bash错误,它们似乎不合适而且与R无关。)