Wednesday, August 10, 2011

Making a progress bar for long R programs

From : http://ryouready.wordpress.com/2009/03/16/r-monitor-function-progress-with-a-progress-bar/

total <- 20
# create progress bar
pb <- txtProgressBar(min = 0, max = total, style = 3)
for(i in 1:total){
Sys.sleep(0.1)
# update progress bar
setTxtProgressBar(pb, i)
}
close(pb)

Tuesday, August 2, 2011

How to concatenate a list of data.frames to obtain a data.frame in R

From http://stackoverflow.com/questions/2851327/r-converting-a-list-of-data-frames-into-one-data-frame :

df <- do.call("rbind", listOfDataFrames)

Monday, August 1, 2011

extract maps in sp format from the maps package in R

from the doc of the package spacetime :

library(maps)
states.m = map('state', plot=FALSE, fill=TRUE)
IDs <- sapply(strsplit(states.m$names, ":"), function(x) x[1])
library(maptools)
states = map2SpatialPolygons(states.m, IDs=IDs)
class(states)
[1] "SpatialPolygons"
attr(,"package")
[1] "sp"