[R] for loop in R
jennifer.sheng2002 at gmail.com
jennifer.sheng2002 at gmail.com
Fri Jan 13 00:36:35 CET 2017
That is right, Bob. Only one loop for now, since I do not know how to set up the 2nd loop. Any advice from the community? Thank you!
Sent from my iPhone
> On Jan 12, 2017, at 4:49 PM, Robert Sherry <rsherry8 at comcast.net> wrote:
>
> 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.
>
> ______________________________________________
> 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