[R] dataframe rbind
David L Carlson
dcarlson at tamu.edu
Fri Dec 4 17:10:19 CET 2015
This will work, although depending on what you are trying to do, there may be a better way:
> DF <- data.frame(a=rnorm(10),b=runif(10),ID=0)
> for (i in 1:10){
+ DF <- rbind(DF, data.frame(a=rnorm(10),b=runif(10),ID=i))}
> str(DF)
'data.frame': 110 obs. of 3 variables:
$ a : num 0.792 0.141 -1.091 -0.918 1.265 ...
$ b : num 0.5935 0.695 0.075 0.0827 0.852 ...
$ ID: num 0 0 0 0 0 0 0 0 0 0 ...
For example:
> DF <- data.frame(a=rnorm(110), b=rnorm(110), ID=rep(0:10, each=10))
> str(DF)
'data.frame': 110 obs. of 3 variables:
$ a : num -1.91926 0.00791 0.65523 0.95019 1.23822 ...
$ b : num 0.344 1.281 2.057 -1.69 -0.268 ...
$ ID: int 0 0 0 0 0 0 0 0 0 0 ...
-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352
-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Troels Ring
Sent: Friday, December 4, 2015 10:03 AM
To: r-help at r-project.org
Subject: [R] dataframe rbind
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.
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.
More information about the R-help
mailing list