Skip to content

joallard/r-cheat-sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

R Cheat Sheet

I don't use R often. Every time I come back to it every few months for some task, I don't remember the basics and less-basics of working with my data, even though I have a rough idea of what I want to do.

Read from CSV

rows = read.csv("rows.csv")

Read from Excel via clipboard

# Data is in clipboard
#
s <- "175   78
179   81
199   91"  # these are not real tabs

data = read.table(text=s, sep="\t") # optional header={TRUE|FALSE}

Get certain rows only

# Slice rows
dataset[1:177,]

# Slice columns
dataset[,5:10]

dataset[dataset$y > 2012]
colMeans(dataset)

summary(data)
names(data)

Plots

plot(x,y)
barplot(v)

Packages

install.packages("corrplot")

Data construction

# (initvalue, rows, columns)
> matrix(0,3,4)
     [,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    0    0    0    0
[3,]    0    0    0    0

> c(4,3,1)
[1] 4 3 1

> 1:4
[1] 1 2 3 4

String

Replace

> sub(" ", "", "1 716.60")
[1] "1716.60"

Tasks

Multiple Regression

Multiple regression

Principal component analysis (PCA)

Computing and visualizing PCA in R (R Bloggers)

d.pca = prcomp(dataset)

summary(d.pca)
biplot(d.pca)

Data types

Vector (programming "Array")

a <- c(2,5,8,9)

summary – Show quartiles and mean

> summary(prices.l45mm.auct)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
  206.6   237.7   257.5   267.9   271.2   564.8

Others

hist - Display histogram

strsplit - Split string on delimiter

strtoi - String to int

Misc

Graphical parameters

About

My R Cheat Sheet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published