[R] How to get an argument dynamically from a list?

From: Stephane Bourgeois <sb20_at_sanger.ac.uk>
Date: Sun, 29 Jun 2008 12:24:16 +0000 (UT)
('binary' encoding is not supported, stored as-is) ('binary' encoding is not supported, stored as-is)

I'd like to get an argument (I think it's the right term) dynamically from a list, but cannot manage to do it.

Here is the code I use:

#output given by database

BOB <- c('A/A', 'C/C', '15/27')
MARY <- c('A/A', NA, '13/12')
JOHN <- c('A/A', 'C/A', '154/35')
CLIFF <- c('A/C', 'C/C', '15/12')

PAM <- c('A/C', 'C/A', '13/12')
sampleList <- c("BOB", "MARY", "JOHN", "CLIFF", "PAM")
polyList <- c("rs123", "rs124", "rs555")

#make dataframe with data

data.raw <- data.frame(t(do.call(data.frame, lapply(sampleList, get)))) names(data.raw) <- polyList
row.names(data.raw) <- sampleList

I want to get, for example, data.raw$rs124 using polyList.

I tried

> get(paste("data.raw$", polyList[2], sep=""))
Error in get(paste("data.raw$", polyList[2], sep = "")) :   variable "data.raw$rs124" was not found   

but it's obviously not the right way, data.raw$rs124 not being a variable per se.

Any idea about how I could do that?



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 Sun 29 Jun 2008 - 12:30:32 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 29 Jun 2008 - 15:01:18 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