0% found this document useful (0 votes)
8 views

r basic cheatsheet

The R Basic Cheat Sheet provides a comprehensive overview of essential R functions for data manipulation, statistical analysis, and visualization. It includes commands for working with arrays, matrices, data frames, and various statistical tests, along with examples of loops and string manipulation. The document serves as a quick reference for users looking to enhance their R programming skills.

Uploaded by

12 yashika pal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

r basic cheatsheet

The R Basic Cheat Sheet provides a comprehensive overview of essential R functions for data manipulation, statistical analysis, and visualization. It includes commands for working with arrays, matrices, data frames, and various statistical tests, along with examples of loops and string manipulation. The document serves as a quick reference for users looking to enhance their R programming skills.

Uploaded by

12 yashika pal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

R Basic Cheat Sheet

by Dipakk (Dipakk) via cheatography.com/67199/cs/16837/

Util Functions Arrays and Matrix (cont) Loops

getwd() gets the working 3D = array(​1:24, dim = 3 dimens​ional for (variable in sequence){ Do for loop
directory c(4,3,2)) array something }
setwd(​"​C:/​fil​e/p​‐ sets the working mat = matrix​(1:12, matrix while (condi​tion){ Do while
ath​") directory nrow=4, ncol=3) something } loop
data = read.c​sv(​fil​‐ opens file explorer to cbind(​mat​1,mat2) column bind if (condi​tion){ Do something } ifelse
e.c​hoo​se()) get data rbind(​mat​1,mat2) row bind else { Do something different } statement
ls() lists the variables
Vector Hypothesis
str(var) structure of the
variable num = c(1,2,​3,4​,5,6) numeric vector t.test​(data) 1 sample t test

rm(var) removes the variable chr = c("a​aa",​"​bbb​") character vector t.test​(da​ta1​,data2) 2 sample t test

help.s​tart() opens help log = c(TRUE​,TR​‐ logical vector t.test​(pr​e,p​ost​,pa​ire​‐ paired sample t

UE,​FALSE) d=TRUE) test


instal​l.p​ack​age​s("p​‐ installs the package
ackage name") mean(vec) mean wilcox.te​st(​data) Wilcox test

librar​y("p​ackage makes the contents sd(vec) standard deviation cor.te​st(​dat​a1,​data2) correl​ation test
name") available to use chisq.t​es​t(data) Chi square test
var(vec) variance
detach​("pa​ckage detaches the shapir​o.t​est​(data) Shapiro test
range(vec) range
name") package
which.m​in​(ve​c)/​whi​‐ position of the aov() ANOVA
ch.m​ax​(vec) min/max value
Strings
Visual​ization
rep(1:​5,t​imes=3) replicate elements
toStri​ng(x) helper function to
of vector qplot(​data, line=T​‐ produces quanti​‐
produce a single
RUE​,...) le-​qua​ntile plot
character string
DataFrame ggplot​(data = NULL, initia​lizes a
touppe​r()​/to​‐ converts text to upper/​‐
df = data.f​ram​e(s​ubj​ect​ID=​‐ dataframe mapping = aes(), ...) ggplot object
lower() lower case
1:5​,ge​nde​r=c​("M",​"​‐ geom_bar() bar graph
substr​ing​(ch​‐ retrieve or replaces the
F","M​"​,"M",​"​F"),​sco​re=​c(8​,3,​‐ coord_​flip() flip x and y
r,n,n) substring of the
6,5,5)) coordi​nates
charachter
view(df) opens facet_​grid() lay out panels in
paste (…, sep = Concat​enate vectors
editor a grid
" ", collapse = after converting to
head(d​f)/​tai​l(df) displays geom_d​ensity density plot
NULL) character
top/bottom
geom_hist histogram
n rows
Arrays and Matrix geom_point scatter plots
summar​y(df) returns
1D = array(​1:24) 1 dimens​ional
descri​ptive
array
statistics of
2D = array(​1:24, dim = 2 dimens​ional data
c(6,4)) array
Descri​ptive Statistics

rowMea​ns(​data[]) row mean


rowSum​s(d​ata[]) row sum
colMea​ns(​data[]) column mean
colSum​s(d​ata[]) column sum

By Dipakk (Dipakk) Published 29th August, 2018. Sponsored by ApolloPad.com


cheatography.com/dipakk/ Last updated 29th August, 2018. Everyone has a novel in them. Finish
Page 1 of 2. Yours!
https://apollopad.com
R Basic Cheat Sheet
by Dipakk (Dipakk) via cheatography.com/67199/cs/16837/

Probab​ility

rbinom(n, size, prob) Binomial distri​‐


bution
rpois(​n,size) Poisson distri​bution
runif(n, min = 0, max Uniform distri​bution
= 1)
rnorm(​n,m​ean,sd) Normal distri​bution
rexp(n) Expone​ntial distri​‐
bution

Statistics

summar​y(lm(y ~ x1 + x2 + multiple
x3, data=m​ydata)) regression
summar​y(glm(y ~ x1 + x2 + classi​fic​‐
x3, family​="", data=m​ydata)) ation
cluster = kmeans​(data) kmeans
cluster
analysis

By Dipakk (Dipakk) Published 29th August, 2018. Sponsored by ApolloPad.com


cheatography.com/dipakk/ Last updated 29th August, 2018. Everyone has a novel in them. Finish
Page 2 of 2. Yours!
https://apollopad.com

You might also like