[R] for loop in R

Jennifer Sheng jennifer.sheng2002 at gmail.com
Thu Jan 12 22:44:03 CET 2017


Dear friends,  I am working on a double loop using for.  One level of loop
is to predict N times for each subject, and the second level is to predict
M times for the every subject, one subject after one subject.   Please note
every subject have different N or M rows of data.   Any advice?  Thank you
so much!

Below is the current code:

set.seed (123)   ## for consistent result;

ND <- S004Cmin[S004Cmin$ID %in% c(1:10),]   # define the first 10 subjects

predSurv <- vector("list", nrow(ND))

for (i in 1:nrow(ND)) {

  set.seed(123)

  predSurv[[i]] <- survfitJM(fitJOINT.NULL, newdata = ND[1:i, ],
idVar="USUBJID")

  }



Thank you very much!

Jenny

	[[alternative HTML version deleted]]



More information about the R-help mailing list