Correct the error in the code
1
0
Entering edit mode
5.4 years ago
mms140130 ▴ 60

Hi I apply the survival analysis in Survival analysis of TCGA patients integrating gene expression (RNASeq) data

and there the code in below

for (i in 1:dim(new_tum)[1]){
ifsumis.na(new_tum[i,])) < dim(new_tum)[2]){
m <- min(new_tum[i,],na.rm=T)
new_tum_collapsed <- c(new_tum_collapsed,m)
} else {
new_tum_collapsed <- c(new_tum_collapsed,'NA')
}
}


but R gave me the following error

> for (i in 1:dim(new_tum)[1]){
+     ifsumis.na(new_tum[i,])) < dim(new_tum)[2]){
Error: unexpected ')' in:
"for (i in 1:dim(new_tum)[1]){
ifsumis.na(new_tum[i,]))"
>         m <- min(new_tum[i,],na.rm=T)
>         new_tum_collapsed <- c(new_tum_collapsed,m)
>     } else {
Error: unexpected '}' in "    }"
>         new_tum_collapsed <- c(new_tum_collapsed,'NA')
>     }
Error: unexpected '}' in "    }"
> }
Error: unexpected '}' in "}"


can you help why?

R • 2.9k views
1
Entering edit mode

R tells you where the error is... Did you read the message?

0
Entering edit mode

You have one extra closing ) in second line before <. Remove that and run again.

0
Entering edit mode

You are right. There is a bug in the tutorial code.

3
Entering edit mode
5.4 years ago

I guess the second line should be :

if ( sum ( is.na ( new_tum[i,] ) )  < dim(new_tum)[2]){


To debug your code yourself, don't be afraid to test it pieces by pieces. The error message in this one was kind of explicit too : every open parenthesis should get closed and vice-versa.

0
Entering edit mode

Thank you very much, can I ask another question about an error for the same survival analysis

pv <- ifelse ( is.na(s1),next,(round(1 - pchisq(s1$chisq, length(s1$n) - 1),3)))[[1]]

Error in ifelseis.na(s1), next, (round(1 - pchisq(s1$chisq, length(s1$n) -  :
no loop for break/next, jumping to top level


can you help correcting this code ,

0
Entering edit mode

As the error states, next is to be used within a loop. Type ?next in the R console for more information.