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@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.

Reply via email to