[R] adding list to data.frame iteratively

Joshua Wiley jwiley.psych at gmail.com
Thu Sep 9 01:08:06 CEST 2010


Hi,

This is not exactly the same, but there was a recent thread on
rbind()ing dataframes from a list:

http://r.789695.n4.nabble.com/Please-explain-do-call-in-this-context-or-critique-to-stack-this-list-faster-td2526908.html

Given that, I wonder if this would work for you:

ll <- list(c("1","2","3"),c("2","3","4"))
dd <- data.frame(matrix(nrow=10,ncol=3))
# rbind() each element of the list together into a data frame
temp <- as.data.frame(do.call("rbind", ll), stringsAsFactors = FALSE)
# assign that dataframe to whichever rows of dd you want
dd[1:2, ] <- temp
# print to screen
dd

Just a thought,

Josh

On Tue, Sep 7, 2010 at 11:17 PM, rajeshj at cse.iitm.ac.in
<rajeshj at cse.iitm.ac.in> wrote:
>
> Hi,
>
> I have a preallocated dataframe to which I have to add a list whose vectors will become rows in the dataframe. This is done iteratively. How can I do this?
> I'm dealing with very large numbers...list of 1000 vectors to a dataframe of 200000 iteratively
>
> for e.g.
> my list is as follows
>
> ll<-list(c("1","2","3"),c("2","3","4"))
>
> I have to add this to a dataframe
> dd<-data.frame(matrix(nrow=10,ncol=3))
>
> so that I get
> 1 2 3
> 2 3 4
> etc.
>        [[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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list