Re: [R] creating a dataframe using a list of the variable names

From: jim holtman <jholtman_at_gmail.com>
Date: Sat, 28 Jun 2008 21:15:08 -0400

Does this do what you want:

> 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")
> x <- do.call(data.frame, lapply(sampleList, get))
> names(x) <- sampleList
> row.names(x) <- polyList
> x

        BOB MARY JOHN CLIFF PAM
rs123 A/A A/A A/A A/C A/C
rs124 C/C <NA> C/A C/C C/A
rs555 15/27 13/12 154/35 15/12 13/12
>

On Sun, Jun 29, 2008 at 3:50 AM, Stephane Bourgeois <sb20_at_sanger.ac.uk> wrote:
> Hello,
>
> I'm fairly new to R, and despite spending quite some time exploring, testing, and looking for answers, I still have a couple of questions remaining...
>
> The first one is about creating a dataframe using a list of the variable names .
>
> I get this output file from a 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")
>
> to create a dataframe with the data I use:
>
> data.raw <- data.frame(BOB, MARY, JOHN, CLIFF, PAM, row.names=polyList)
>
> which works fine, but when there are several hundreds samples... well, you guess my problem.
>
> I'd like to create the dataframe using the list of the variables, contained in sampleList - i.e. something like data.frame(function(sampleList), row.names=polyList)
>
> Is that possible, and if yes, how?
>
> Thanks in advance,
>
> 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.
>
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
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 - 01:18:55 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 - 06:31:55 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