[R] Problem with by(... , median)
Michal Figurski
figurski at mail.med.upenn.edu
Tue Jun 10 16:21:12 CEST 2008
Well,
Yes, that works just fine! Thank you!
--
Michal J. Figurski
HUP, Pathology & Laboratory Medicine
Xenobiotics Toxicokinetics Research Laboratory
3400 Spruce St. 7 Maloney
Philadelphia, PA 19104
Henrique Dallazuanna wrote:
> Try using aggregate:
>
> aggregate(tb[-1], list(tb$Subject), FUN=median, na.rm = T)
>
> On Tue, Jun 10, 2008 at 10:18 AM, Michal Figurski
> <figurski at mail.med.upenn.edu <mailto:figurski at mail.med.upenn.edu>> wrote:
>
> Hello everyone,
>
> I am new to R, I have been using SAS for a while. Not surprisingly,
> I find R much better in graphics, which is publication ready right away.
>
> Recently, I have been trying to calculate some basic statistics
> using R. I have a dataset of multiple rows per subject. For example:
>
> Subject Date Factor1 Factor2 Factor3
> P1 0.5 1 1 3
> P1 1 3 2 5
> P1 2 3 5 NA
> ...
> P2 0.5 1 6 4
> P2 1 2 NA 7
> P2 2 3 1 2
> ...
>
> I wanted to get the 'by subject' statistics of the factors. I used
> the following code: a=by(dat1, dat1$Subject, mean, na.rm=TRUE) -
> this is for a mean.
> However, when I try that with a 'median', I get an error message. It
> is strange to me, because with the 'summary' option, I get the
> median values for all factors separately, among other information.
> What I need is just a median, because I later need it for plotting.
> I have read old posts on the archive, and I agree that the action of
> 'median' is according to the documentation. However, I think this is
> a serious inconvenience, and it should be changed to work in the
> same way as mean, summary or sd options.
>
> Nevertheless, accepting the reality, I have a question to all: how
> to obtain the by-subject medians of factors in such dataset?
>
> Thanks in advance,
>
> --
> Michal J. Figurski
> HUP, Pathology & Laboratory Medicine
> Xenobiotics Toxicokinetics Research Laboratory
> 3400 Spruce St. 7 Maloney
> Philadelphia, PA 19104
>
> ______________________________________________
> R-help at r-project.org <mailto:R-help at r-project.org> mailing list
> 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.
>
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list