Biostar Beta. Not for public use.
Correct the error in the code
0
Entering edit mode
2.5 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 • 927 views
ADD COMMENTlink
1
Entering edit mode

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

ADD REPLYlink
0
Entering edit mode

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

ADD REPLYlink
0
Entering edit mode

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

ADD REPLYlink
3
Entering edit mode
13 months ago
Carlo Yague ♦ 4.5k
Belgium

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
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 REPLYlink
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 REPLYlink

Login before adding your answer.

Similar Posts
Loading Similar Posts
Powered by the version 2.1