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

From: stephen sefick <ssefick_at_gmail.com>
Date: Sun, 29 Jun 2008 09:03:37 -0400

x <- as.matrix(data.raw)
x[,2]

is this what you want?
BOB MARY JOHN CLIFF PAM
"C/C" NA "C/A" "C/C" "C/A"

On Sun, Jun 29, 2008 at 3:24 PM, Stephane Bourgeois <sb20_at_sanger.ac.uk> wrote:

> Hi,
>
> 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?
>
> Thanks,
>
> Stephane
>
> ______________________________________________
> 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.
>
>

-- 
Let's not spend our time and resources thinking about things that are so
little or so large that all they really do for us is puff us up and make us
feel like gods. We are mammals, and have not exhausted the annoying little
problems of being mammals.

-K. Mullis

	[[alternative HTML version deleted]]

______________________________________________
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 - 13:06:48 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 - 13:30:47 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