Question: Correct the error in the code
0
gravatar for mms140130
21 months 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 • 796 views
ADD COMMENTlink modified 21 months ago • written 21 months ago by mms14013060
1

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

ADD REPLYlink written 21 months ago by PoGibas4.7k

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

ADD REPLYlink written 21 months ago by venu5.8k

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

ADD REPLYlink written 21 months ago by russhh4.2k
3
gravatar for Carlo Yague
21 months ago by
Carlo Yague4.4k
Belgium
Carlo Yague4.4k 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 21 months ago • written 21 months ago by Carlo Yague4.4k

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 21 months 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 21 months ago by Carlo Yague4.4k
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: 1391 users visited in the last hour