Skip to content

Instantly share code, notes, and snippets.

@lukmdo
Last active December 11, 2015 17:19
Show Gist options
  • Save lukmdo/4634074 to your computer and use it in GitHub Desktop.
Save lukmdo/4634074 to your computer and use it in GitHub Desktop.
R notes
### Plots
x <- seq(0, 4, 0.1)
y <- cos(x)
plot(x, y, col=rainbow(12)) # 2-RED, 3-GREEN, 4-BLUE
a <- c(5, 8, 3); names(a)<- c("England", "France", "Norway"); barplot(a)
abline(h, v, lty=3, col="lightgray")
barplot(sin(seq(0, 4, 0.1)))
qplot(Xvect, Yvects)
qplot(weights, prices, col=factor(types))
abline(lm(X~Y))
summary(lm(Y~X))
### Matrixes
mx <- matrix(DATA, N, M)
matrix(1, 3, 4)
matrix(1:12, 3, 4)
dim(mx)
mx[RowNum,] / mx[,ColNum]
mx[RowNum, ColNum] <- "VAL" / mx[RowNum:RowNum+N, ColNum] <- "VAL"
### Matrixes-Vis
persp(px, expand=0.2)
contour(volcano)
image(mx)
### Statstics
mean, median, sum
deviation <- sd(pounds)
abline(h = meanValue + deviation)
### Files
list.files()
read.table("FILEPATH.txt", sep="\t", header=TRUE)
read.csv("FILEPATH.csv")
merge(OneList, OtherList)
### Books
- http://www.cookbook-r.com
- http://www.r-tutor.com
# http://nsaunders.wordpress.com/2010/08/20/a-brief-introduction-to-apply-in-r/
lapply
sapply
apply
tapply
mapply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment