Correct the error in the code
1
0
Entering edit mode
7.6 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)
Error: object 'i' not found
>         new_tum_collapsed <- c(new_tum_collapsed,m)
Error: object 'm' not found
>     } else {
Error: unexpected '}' in "    }"
>         new_tum_collapsed <- c(new_tum_collapsed,'NA')
>     }
Error: unexpected '}' in "    }"
> }
Error: unexpected '}' in "}"

can you help why?

R • 4.6k views
ADD COMMENT
1
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
3
Entering edit mode
7.6 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.

ADD COMMENT
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 ,

ADD REPLY
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.

ADD REPLY

Login before adding your answer.

Traffic: 1953 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6