在我编写的代码中,我正在尝试分析稀疏矩阵(mat)中所有行的每行真值的数量,我在尝试运行if语句时遇到了困难。
counter=0
geneCount=0
columnIndex=-1
cols=20
rows=20
for (col in 0:cols){
columnIndex=columnIndex+1
for (row in 0:rows){
for (col in 0:cols){
if (mat[row,col] = TRUE){
counter=counter+1
}
if(counter = 2){
sigArray[columnIndex]=sigArray[columnIndex]+1
counter=0
next
}
}
}
}我一直收到错误消息:
Error: unexpected '=' in:
" for (col in 0:cols){
if (mat[row,col] ="用于第一个if语句。我尝试过使用双等号,但也不起作用。
谢谢!
发布于 2017-02-24 03:45:46
至少有两个问题。正如您所想,第一个问题是if语句是逻辑测试,因此需要相等测试运算符。您需要使用==来测试相等性。第二个问题是行和列的R索引以1开头,而不是0。因此,假设您的数据集中实际有21行和21列(即,从0到20就可以工作),我认为您应该像这样编辑语法:
counter=0
geneCount=0
columnIndex=0
cols=21
rows=21
for (col in 1:cols){
columnIndex=columnIndex+1
for (row in 1:rows){
for (col in 1:cols){
if (mat[row,col] == TRUE){
counter=counter+1
}
if(counter == 2){
sigArray[columnIndex]=sigArray[columnIndex]+1
counter=0
next
}
}
}
}https://stackoverflow.com/questions/42424637
复制相似问题