Re: [R] creating a "list of 3 dataframes" from a "list of 2 dataframes" and a dataframe?

From: Petr Klasterecky <klaster_at_karlin.mff.cuni.cz>
Date: Mon, 14 May 2007 23:25:31 +0200

Rajarshi Guha napsal(a):
> On May 14, 2007, at 2:48 PM, new ruser wrote:
>

>> #I wish to create a "list of three dataframes" ("results2")  from a  
>> "list of two dataframes" (temp) and a dataframe ("c")?
>>
>> #Please advise.
>>
>> a <- data.frame(x=c(1,2,3),y=c(5,7,9))
>> b <- data.frame(x=c(2,4,7,9),y=c(2,3,5,4))
>> c <- data.frame(x=c(22,34,7,9),y=c(52,63,5,4))
>> results1 <- list(a,b,c) #what I want
>>
>> #but this is how I need to get there
>> temp <- list(a,b)
>> #results2 <- fun?????(temp2,c) # I need help here

>
> temp[[ length(temp) + 1 ]] <- c
> results2 <- temp

A MUCH cleaner solution comes directly from the help for c():

## append to a list:

      ll <- list(A = 1, c="C")
      ## do *not* use
      c(ll, d = 1:3) # which is == c(ll, as.list(c(d=1:3))
      ## but rather
      c(ll, d = list(1:3))# c() combining two lists

So in your case
results2 <- c(temp, list(c))

Petr

>
> -------------------------------------------------------------------
> Rajarshi Guha <rguha@indiana.edu>
> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
> -------------------------------------------------------------------
> Does Ramanujan know Polish?
> -- E.B. Ross
>
> ______________________________________________
> R-help_at_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
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic

______________________________________________
R-help_at_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
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 14 May 2007 - 21:32:11 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 Mon 14 May 2007 - 22:31:25 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.