Re: [R] data.frame or list

From: baptiste Auguié <ba208_at_exeter.ac.uk>
Date: Sat, 05 Apr 2008 23:15:33 +0100

Hi again,

Is this approach correct, or should I rather use only one type of factors (combined)? I must admit I am a bit confused by the different options to store and manipulate data in R. As I understand, data.frames are the preferred format, but I can't see how to frame this example data in it (hence my resort to a list). Any advice welcome (or reference).

baptiste

PS: off topic, why would it be that i receive messages from this list but cannot anymore post without some "approval" being required? This is probably a weird technical glitch of mine, I can't imagine my few questions to this list having caused any inconvenience.

On 3 Apr 2008, at 11:27, baptiste Auguié wrote:
> 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
> ______________________________
>
>
>
>
>


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 Sat 05 Apr 2008 - 22:32:46 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 Sat 05 Apr 2008 - 23:30:26 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