[R] Getting univariate information from a multivariate data set

Jarrett Byrnes jebyrnes at ucdavis.edu
Sat Oct 22 21:37:04 CEST 2005


A quick question that I've had only partial success in answering.  I 
have a multivariate dataset, and would like to extract some simple 
univariate information from it grouped by treatments, etc.  I am 
encountering two problems however
Note: I am importing my data with
my_data <- read.csv("/path/data.csv")

1) Scoping of unstack

If I attempt

sorted_data <- unstack(response, response ~ treatment, data=my_data)

I get

Error in unstack(response, response ~ treatment, data=my_data): Object 
response not found

However, if I first use attatch(my_data) and drop the data statement in 
unstack, I'm fine.  This is all well and good, but I often work with 
multiple data sets with similar column headings, and would rather not 
have to attach and detach over and over again.

2) getting the univariate data

Once, I attach, I find that I cannot then easily just use mean, sd, or 
anysuch, as

mean(sorted_data)

yields

argument is not numeric or logical: returning NA in: mean.default(a)

Nor does something like mean(sorted_data[1]) work - I thought perhaps 
breaking it down by treatment might help.


Thanks in advance for any help!

-Jarrett


----------------------------------------
Jarrett Byrnes
Population Biology Graduate Group, UC Davis
Bodega Marine Lab
707-875-1969
http://www-eve.ucdavis.edu/stachowicz/byrnes.shtml




More information about the R-help mailing list