[R] save output of loop

johnmark johnmark.agosta at gmail.com
Tue Feb 14 16:59:56 CET 2012


The short answer to your question is *don't* concatenate the values in the
row, then attempt to /rbind()/ them incrementally to a data.frame.  Instead
build each column separately inside the loop, then /cbind() (data.frame()/ 
does an implicit/ cbind()/ ) them together at the end.  Something like this:

/
lat.column <- c(length(100))
lon.column <- c(length(100))
...
for (i in 1:100){ 
 ...
  lat.column[i]  <- data[,7] # latitude 
  lon.column[i] <- data[,8] # longitude 
   ...
} 
my.data <- data.frame(lat.column, lon.column, ...)
/

-jm


--
View this message in context: http://r.789695.n4.nabble.com/save-output-of-loop-tp4386599p4387476.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list