Publications by Forester
Calculate turning angles and step lengths from location data
anglefun <- function(xx,yy,bearing=TRUE,as.deg=FALSE){ ## calculates the compass bearing of the line between two points ## xx and yy are the differences in x and y coordinates between two points ## Options: ## bearing = FALSE returns +/- pi instead of 0:2*pi ## as.deg = TRUE returns degrees instead of radians c = 1 if (as.deg){ ...
911 sym R (1836 sym/1 pcs)
Convert image to matrix in R
This is how to use the Pixmap library to read in an image as a matrix.> library(pixmap) # the next command may only work on Linux > system("convert foo.tiff foo.ppm") > img <- read.pnm("foo.ppm") To get info on your new object: > str(img) Although included in the previous output, the size of the image can be extracted by:>[email pr...
730 sym R (289 sym/5 pcs)
Repeat elements of a vector
Two methods. The first produces a vector, the second a one column matrix.x=1:10# Method 1rep(x,each=3)# Method 2matrix(t(matrix(x,length(x),3))) Related To leave a comment for the author, please follow the link and comment on their blog: Quantitative Ecology. R-bloggers.com offers daily e-mail updates about R news and tutorials a...
561 sym
Visualizing Data
Sometimes it is helpful to see the plots created from the example files within R libraries. Of course you can paste them directly into R, but this web page allows you to view the images within the context of the help files:R Graphical ManualsAlso, check out this link for the R Graph Gallery. Related To leave a comment for the autho...
709 sym
Variance-Covariance Matrix in glm
This is a small function Venables and Ripley provide in their MASS book. You don’t need it anymore because vcov() has a method for the glm class. However, it is useful to see how to extract bits from a fitted model object.vcov.glm<-function(obj){ #return the variance-covariance matrix of a glm object #from p. 188 in Venables and...
637 sym R (251 sym/1 pcs)
Including arguments in R CMD BATCH mode
When you have multiple computers or processors at your disposal and wish to run the same script with different arguments, use the following at the command line (here described for Linux; remove the linebreak, it is just there for display purposes):$ R CMD BATCH --no-save --no-restore '--args a=1 b=c(2,5,6)' test.R test.out & Where tes...
1000 sym R (590 sym/3 pcs)
Offset in glm ()
To add an offset to the linear predictor of a generalized linear model (or models from the survival package such as coxph and clogit), use offset(x) in the formula. This will add an offset to the linear predictor with known coefficient 1. Related To leave a comment for the author, please follow the link and comment on their blog: ...
655 sym
Execute system commands within an R Script
To execute a system command from within an R script, just use system(). This is handy for zipping large output files on the fly.write.csv(mydat, "mydat.csv") system("gzip mydat.csv", wait=FALSE) Related To leave a comment for the author, please follow the link and comment on their blog: Quantitative Ecology. R-bloggers.com offers ...
543 sym R (67 sym/1 pcs)
Extract objects from a list
When using Rmpi to send processes to many nodes, it is convenient to create a list of tasks that are assigned to nodes as they become available. In my case, I was working through a large factorial set of simulations and needed to use a unique set of variable values for each task. Rather than assign these variables individually within ...
949 sym R (377 sym/1 pcs)
Reorder factor levels
Very often, especially when plotting data, I need to reorder the levels of a factor because the default order is alphabetical. There must be many ways of reordering the levels; however, I always forget which package to look in. A direct way of reordering, using standard syntax is as follows:## generate data x = factor(sample(letters[1...
978 sym R (306 sym/1 pcs)