Question: Correct the error in the code
0
gravatar for mms140130
2.1 years ago by
mms14013060
mms14013060 wrote:

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 • 915 views
ADD COMMENTlink modified 2.1 years ago • written 2.1 years ago by mms14013060
1

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

ADD REPLYlink written 2.1 years ago by PoGibas4.8k

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

ADD REPLYlink written 2.1 years ago by venu6.2k

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

ADD REPLYlink written 2.1 years ago by russhh4.4k
3
gravatar for Carlo Yague
2.1 years ago by
Carlo Yague4.5k
Belgium
Carlo Yague4.5k wrote:

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 COMMENTlink modified 2.1 years ago • written 2.1 years ago by Carlo Yague4.5k

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 REPLYlink written 2.1 years ago by mms14013060

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

ADD REPLYlink written 2.1 years ago by Carlo Yague4.5k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1146 users visited in the last hour