I'm trying to subset my current data frame with a new data frame that lists genes I'm investigating in one column and p-values in another (for each gene).
I have a data frame called m3 that looks like below:
Sample # BRCA TP53 MYC Status Overall Survival
1 0 1 1 0 5.8
2 1 0 0 1 8.4
3 0 0 1 1 2.2
4 0 0 0 0 16.2
The dimensions of my actual data frame are 72 x 258. I'm trying to loop through each column and calculate the p-value for the survival analysis I am running. I'm trying to determine if having a specific mutation will result in a statistically significant survival difference. I denote a patient has a mutation by 1 for each gene.
I have written a survival function for just one column, but I want to loop through each one and then ultimately subset it to create a new data frame. I am unsure if it would be wise to use the apply function (I have read that is common) or to use a for loop.
survfit(Surv(m3$Overall.Survival, m3$Status) ~m3$BRCA2, data = m3
I tried this initially, but it did not work...
for (col in 2:ncol(m3) ){surv.mod.list[col] <- survfit(S ~ m3[ , col], data = m3)}
Can you please help me with my loop?