Snippets of code for things you do all the time in R
4dpiecharts.com
4dpiecharts.com
(if there already is on the site you linked to, sorry for being obtuse).
Simple example to show when '=' won't work but '<-' will. Pilfered from "R Inferno" [2], which is an excellent reference for R idioms and best practices.
system.time(vec1 <- rnorm(1000))
mean(vec1)
system.time(vec2 = rnorm(1000))
mean(vec2)
And to demonstrate that you need to use '=' for argument passing: x <- c(3,4,NA)
mean(x)
mean(x, na.rm=TRUE)
mean(x, na.rm<-TRUE)
[1] Type help('=') at an R prompt, or view it online: http://stat.ethz.ch/R-manual/R-patched/library/base/html/ass...[2] http://www.burns-stat.com/pages/Tutor/R_inferno.pdf
edit: clarified statement.
edit: added examples.
Do you have an example of where it would be required to use '<-'? Not just median(x <- 10), but a use in which there no simple '=' alternative.
This applies in all languages:
vec1 = rnorm(100)
system.time(vec1)
mean(vec1)
And, I can get my colleagues to fix it when I screw up, even though they are not R-heads.
> system.time(vec1 <- rnorm(1000000))
user system elapsed
0.200 0.000 0.199
My computer takes .2 seconds to generate the million random normals and assign them to vec1. > vec1 = rnorm(1000000)
> system.time(vec1)
user system elapsed
0 0 0
My computer only takes 0 seconds to evaluate the existing vec1 of length one million.