[R] for loop in R

Robert Sherry rsherry8 at comcast.net
Thu Jan 12 22:49:17 CET 2017


I only see one for loop in your code. I am wondering if you want a 
second for loop based upon the length of newdata.

I would also think that you do not need the second call to set.seed.

Bob

On 1/12/2017 4:44 PM, Jennifer Sheng wrote:
> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list