[R] extracting values from data.frame given arbitrary keys

From: Antonio, Fabio Di Narzo <antonio.fabio_at_gmail.com>
Date: Fri 19 May 2006 - 00:04:08 EST

Hi all.
I have a pure R programming question.
Having a data.frame with a 'data' variable and some (>1) ID variables
(either numeric or factors), I would extract a sequence of data values given
a sequence of ID values.

Here's an example. Build a dataset:

n1 <- 5
n2 <- 2
v1 <- rep(factor(1:n1),2)
v2 <- rep(1:n2,5)

x <- rnorm(10)
dat <- data.frame(x=x, v1=v1, v2=v2)

Now, for example, I should extract x values responding to some arbitrary IDs:
(v1="2", v2=1), (v1="3", v2=2), (v1="4", v2=1).
For example, I should store those id sequences in a separate list (maybe an indexing data.frame), but this really isn't the point. The point is that I have somewhere a ready sequence of IDs from which obtaining corresponding data.
Note that I don't know if some ID combination exists in the database. Some suggestions on a good way to do this?

Tnx all,
Antonio, Fabio Di Narzo.

        [[alternative HTML version deleted]]

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 Fri May 19 00:10:36 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 19 May 2006 - 04:10:14 EST.

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