[R] dataframe rbind

peter dalgaard pdalgd at gmail.com
Fri Dec 4 17:13:35 CET 2015


On 04 Dec 2015, at 17:03 , Troels Ring <tring at gvdnet.dk> wrote:

> Dear friends - I have a very simple question -
> I generate a number of dataframes with identical names and want to combine them into one large dataframe with the same names -
> here is an example
> 
> DF <- data.frame(a=rnorm(10),b=runif(10),ID=0)
> for (i in 1:10){
> DF <- DF+rbind(data.frame(a=rnorm(10),b=runif(10),ID=i))}
> 
> - the dataframe do not grow as I thought it would.
> 

Don't you mean DF <- rbind(DF, data.frame(...... ?

(Or, but a different discussion, do.call("rbind", lapply(1:10, function(i) data.frame(.....,ID=i)))

-pd


> How would I do this?
> 
> All best wishes
> Troels Ring
> Nephrology
> Aalborg
> Denmark
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list