[R] Data frames questions

Wensui Liu liuwensui at gmail.com
Sun Sep 24 02:28:43 CEST 2006


> 3) How to I "append" to the bottom of a dataframe?

APPEND ROWS ITERATIVELY TO A DATA FRAME

#################################################
# APPEND ROWS ITERATIVELY TO A DATA FRAME       #
#################################################

# LOOP FROM 1 TO 10
for(i in 1:10)
{
  # SET THE RANDOM STATE
  set.seed(i);
  # CREATE A DUMMY DATA FRAME ITERATIVELY
  data<-data.frame(iter = i, x = rnorm(1), y = runif(1));
  # ASSIGN THE ROW NAME
  row.names(data)<-i;
  # APPEND NEW DATA TO THE END OF MAIN DATA FRAME
  if (i == 1) main<-data else main<-rbind(main, data);
};



More information about the R-help mailing list