[R] Problem with by(... , median)

From: Michal Figurski <figurski_at_mail.med.upenn.edu>
Date: Tue, 10 Jun 2008 09:18:22 -0400

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 mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 10 Jun 2008 - 13:27:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 10 Jun 2008 - 14:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive