[R] data.frame or list

From: baptiste Auguié <ba208_at_exeter.ac.uk>
Date: Thu, 03 Apr 2008 11:27:03 +0100


Dear R list,

I'm having difficulties in choosing between a list or a data.frame, or an array for the storage and manipulation of my data (example follows). I've been using the three for different purposes but I would rather like to know which is more adapted to what task.

Here is the data I'm currently working on: 200 observations, each observation being a vector of length 1000 depending on several factors ("polarisation", "pitch", "dose", "size")

> x <- seq(1,100,length = 1000)
> observations <- matrix( rnorm(200*1000), ncol = 200)
>
> # factors
> polarisation <- rep(c("0","90"), each = 100, length = 200)
> pitch <- rep(1:5, length = 200)
> dose <- rep(1:2, each =100, length = 200)
> size <- rep(letters[1:6], each =100, length = 200)
>
> my.data <- list(x = x,
> observations = as.data.frame(observations),
> polarisation = factor(polarisation),
> pitch = factor(pitch),
> dose = factor(dose),
> size = factor(size))

I would like to be able to manipulate the data in "observations" using the factors as opposed to column indices. For instance, I could plot all the observations corresponding to polarisation == "90" and pitch == "1", like in,

> with(my.data , matplot(x, subset((pitch == "1") & (polarisation ==
> "90"), observations, type="l" )))

which doesn't work, so I've had to use,

> with(my.data , matplot(x, observations[,(pitch == "1") &
> (polarisation == "90")], type="l" ))

Is this a sensible way to store and manipulate this sort of data? Is there anything more appropriate I've overlooked using data.frames only?

Many thanks,

baptiste


Baptiste Auguié

Physics Department
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag
http://projects.ex.ac.uk/atto



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. Received on Thu 03 Apr 2008 - 10:37:51 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 Sun 06 Apr 2008 - 01:30:25 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