[R] Getting univariate information from a multivariate data set

From: Jarrett Byrnes <jebyrnes_at_ucdavis.edu>
Date: Sun 23 Oct 2005 - 05:37:04 EST

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



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 Byrnes
Population Biology Graduate Group, UC Davis Bodega Marine Lab

R-help@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 Received on Sun Oct 23 05:42:02 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 19:18:20 EST