[R] [basic ?] Merging result of by processing with a data fra me
Liaw, Andy
andy_liaw at merck.com
Mon Jan 17 15:46:15 CET 2005
> From: Jean-Louis Abitbol
>
> Dear All,
>
> I would like to merge a data frame such as:
>
> > basetab
> subject dose cmax
> 1 1031 50 21.8
> ....
>
> with the result of a by processing such as:
>
> > tmax<-by(pkga,subject,f.tmax)
> > tmax
> subject: 1031
> [1] 6
> --------------------------------------------------
>
> f.tmax being a function written by H. Nguyen (in applied statistics in
> the pharmaceutical industry). pkga is a data frame with subject conc
> time variates.
>
> The aim is to have a single data frame with subject dose cmax tmax etc
> (AUCs) ... so that I can do summary stats and plots by dose.
I would use tapply() instead of by(). Something like the following might
work (assuming `subject' is factor, as I believe it should be):
tmax <- tapply(pkga, subject, f.tmax)
tmax <- data.frame(subject=factor(names(tmax), tmax=tmax)
Then use merge() to merge basetab with tmax, or if all subjects are present
and in the same order, just cbind() them.
Andy
> I have tried unlist without success.
>
> Thanks for any help.
>
> Kind regards, Jean-Louis
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list