I'd like to run the below code for my table, but instead of defining "ind_gene" as a single row name and running everything based on that, I want to run mass survival analysis and extract the p-value for every gene listed in rownames(z_rna), and have R return the results to me as a list. Could anyone please point me towards a method to do this?
# pick your gene of interest
ind_gene <- which(rownames(z_rna) == "TP53")
# run survival analysis
s <- survfit(Surv(as.numeric(as.character(all_clin$new_death))[ind_clin],all_clin$death_event[ind_clin])~event_rna[ind_gene,ind_tum])
s1 <- tryCatch(survdiff(Surv(as.numeric(as.character(all_clin$new_death))[ind_clin],all_clin$death_event[ind_clin])~event_rna[ind_gene,ind_tum]), error = function(e) return(NA))
# extract the p.value
pv <- ifelseis.na(s1),next,(round(1 - pchisq(s1$chisq, length(s1$n) - 1),3)))[[1]]
Thanks so much!
Have a look at apply().
There is a missing parenthesis in the last row, between ifelse and is.na.
My two cents is to do this on tables instead of lists.