© All Rights Reserved

98 views

© All Rights Reserved

- Advance R Cheat sheet
- r Cheat Sheet
- r Studio Cheat Sheet
- R Studio Cheat Sheet for Math1041
- Effect of Gender on Short Term Memory Finished
- Course Project - Part B
- COMP2614Assign01
- 35..
- [the SAS Technical Team Writers]
- VanLeerRichardson READ6407 AR Proposal
- Data Pre Processing in WEKA
- Definition of Business Policy 1st unit.docx
- bb 9.1 new
- stats homework 2 key
- KNOW THE PREFERENCE OF CONSUMER ON HERO-HONDA TWO-WHEELERSort
- KNOW THE PREFERENCE OF CONSUMER ON HERO-HONDA TWO-WHEELERS
- main panel
- gnuplot (2)
- Articulo Actitud Del Granjero y Ba
- 14631graphingcalculatorspart2-161017020921

You are on page 1of 2

Cheat Sheet

Getting Help

Accessing the help files

?mean

Get help of a particular function.

help.search(weighted mean)

Search the help files for a word or phrase.

help(package = dplyr)

Find help for a package.

str(iris)

Get a summary of an objects structure.

class(iris)

Find the class an object belongs to.

library(dplyr)

its functions available to use.

dplyr::select

data(iris)

Working Directory

setwd(C://file/path)

2 4 6

2:6

2 3 4 5 6

An integer

sequence

seq(2, 3, by=0.5)

A complex

sequence

While Loop

while (condition){

Do something

Do something

Example

Example

for (i in 1:4){

rep(1:2, times=3)

1 2 1 2 1 2

Repeat a vector

rep(1:2, each=3)

1 1 1 2 2 2

Repeat elements

of a vector

j <- i + 10

print(i)

print(j)

i <- i + 1

Vector Functions

sort(x)

Return x sorted.

table(x)

See counts of values.

rev(x)

Return x reversed.

unique(x)

See unique values.

Functions

If Statements

if (condition){

Do something

} else {

Do something different

}

Do something

}

return(new_variable)

Example

Example

By Position

x[4]

if (i > 3){

print(Yes)

} else {

x[-4]

x[2:4]

x[-(2:4)]

two to four.

x[c(1, 5)]

five.

print(No)

return(squared)

}

Input

Ouput

Description

write.table(df, file.txt)

file.

df <- read.csv(file.csv)

write.csv(df, file.csv)

separated value file. This is a

special case of read.table/

write.table.

load(file.RData)

file type special for R.

df <- read.table(file.txt)

By Value

x[x == 10]

Elements which

are equal to 10.

x[x < 0]

than zero.

x[x %in%

c(1, 2, 5)]

Use projects in RStudio to set the working

directory to the folder you are working in.

a vector

c(2, 4, 6)

getwd()

inputs are found and outputs are sent).

For Loop

Creating Vectors

Using Libraries

install.packages(dplyr)

Programming

Vectors

1, 2, 5.

Named Vectors

x[apple]

Element with

name apple.

Conditions

a == b

Are equal

a > b

Greater than

a >= b

Greater than

or equal to

is.na(a)

Is missing

a != b

Not equal

a < b

Less than

a <= b

Less than or

equal to

is.null(a)

Is null

Types

Converting between common data types in R. Can always go

from a higher value in the table to a lower value.

Matrixes

Strings

Create a matrix from x.

as.numeric

numbers.

1, 0, 1

as.character

preferred to factors.

as.factor

levels: '1', '0'

levels. Needed for some

statistical models.

log(x)

Natural log.

sum(x)

Sum.

exp(x)

Exponential.

mean(x)

Mean.

max(x)

Largest element.

median(x)

Median.

min(x)

Smallest element.

quantile(x)

Percentage

quantiles.

Round to n decimal

places.

rank(x)

Round to n

significant figures.

var(x)

Correlation.

sd(x)

round(x, n)

sig.fig(x, n)

cor(x, y)

Rank of elements.

The variance.

] - Select a row

m[ , 1] - Select a column

m[2, 3] - Select an element

The standard

deviation.

> a

[1] 'apple'

l[1]

l$x

l['y']

Second element

of l.

only the first

element.

Element named

x.

only element

named y.

dplyr library.

Data Frames

A special case of a list where all elements are the same length.

x

The Environment

ls()

environment.

rm(x)

environment.

Matrix subsetting

head(df)

rows.

df[2, 2]

toupper(x)

Convert to uppercase.

tolower(x)

Convert to lowercase.

nchar(x)

factor(x)

Turn a vector into a factor. Can

set the levels of the factor and

the order.

cut(x, breaks = 4)

Turn a numeric vector into a

factor but cutting into

sections.

Statistics

lm(x ~ y, data=df)

Linear model.

glm(x ~ y, data=df)

Generalised linear model.

summary

Get more detailed information

out a model.

df[2, ]

t.test(x, y)

Preform a t-test for

dierence between

means.

pairwise.t.test

Preform a t-test for

paired data.

prop.test

Test for a

dierence

between

proportions.

aov

Analysis of

variance.

Distributions

See the full data

frame.

environment.

browse variables in your environment.

df[[2]]

df$x

View(df)

df[ , 2]

Factors

l[[2]]

grep(pattern, x)

Lists

List subsetting

Variable Assignment

rm(list = ls())

w

w

w

ww

w

w

w

w

ww

w

w

w

w

ww

w

t(m)

Transpose

m %*% n

Matrix Multiplication

solve(m, n)

Find x in: m * x = n

A list is collection of elements which can be of dierent types.

Maths Functions

m[2,

as.logical

nrow(df)

Number of rows.

ncol(df)

Number of

columns.

dim(df)

Number of

columns and

rows.

Random

Variates

Cumulative

Distribution

Quantile

Normal

rnorm

dnorm

pnorm

qnorm

Poison

rpois

dpois

ppois

qpois

Binomial

rbinom

dbinom

pbinom

qbinom

Uniform

runif

dunif

punif

qunif

Plotting

rbind - Bind rows.

Density

Function

plot(x)

Values of x in

order.

Dates

plot(x, y)

Values of x

against y.

hist(x)

Histogram of

x.

- Advance R Cheat sheetUploaded byAlaskaTar3
- r Cheat SheetUploaded byHaritha Atluri
- r Studio Cheat SheetUploaded bySuren Markosov
- R Studio Cheat Sheet for Math1041Uploaded byOliver
- Effect of Gender on Short Term Memory FinishedUploaded byhafsah286
- Course Project - Part BUploaded byParker DKD
- COMP2614Assign01Uploaded byjt350
- 35..Uploaded byMayank Paneliya
- [the SAS Technical Team Writers]Uploaded bymohuna
- VanLeerRichardson READ6407 AR ProposalUploaded byvanleerlc
- Data Pre Processing in WEKAUploaded byPrashant Suneja
- Definition of Business Policy 1st unit.docxUploaded byManik Kanwal
- bb 9.1 newUploaded byfranbimari
- stats homework 2 keyUploaded byapi-201648540
- KNOW THE PREFERENCE OF CONSUMER ON HERO-HONDA TWO-WHEELERSortUploaded byakucool143
- KNOW THE PREFERENCE OF CONSUMER ON HERO-HONDA TWO-WHEELERSUploaded byakucool143
- main panelUploaded byapi-283145519
- gnuplot (2)Uploaded by윤병택
- Articulo Actitud Del Granjero y BaUploaded byHéctor
- 14631graphingcalculatorspart2-161017020921Uploaded byJasMisionMXPachuca
- Exercise 01Uploaded byishanelite
- GOOGLE ClassroomUploaded byRonaldo de Paulli
- Test of Homogeneity Based on Geometric Mean of VariancesUploaded byGlobal Research and Development Services
- An_exploratory_visualization_of_expert_c.pdfUploaded byTarcizio Macedo
- RUploaded byankit_jolly_2
- R Help 3 Getting HelpUploaded byAnna
- 22-1-44-1-10-20170102.pdfUploaded byikhsan junior
- Beaver Pond ReportUploaded byMichael Kazi
- TV40303_5Uploaded bytanakborneo
- Final Data AnalysisUploaded byharvey aguilar

- The Civilizing ProcessUploaded byaespinosa232
- Sampling in social networksUploaded byluanamdonascimento
- The Majority Illusion in Social Networks.pdfUploaded byluanamdonascimento
- ForceAtlas2 - A Continuous Graph Layout Algorithm.PDFUploaded byluanamdonascimento
- Chapter 04 RUploaded byAdriancisneros Pel
- Crime&Inequality.pdfUploaded byluanamdonascimento
- A User s Guide to Network Analysis in RUploaded byluanamdonascimento
- 14-Learning-Decision-Trees.pdfUploaded byluanamdonascimento
- Ga Moran 2016Uploaded byluanamdonascimento
- 2010 ReviewUploaded byPumbaa Peng
- (000) Kostakis - Study of 3 Deliberation Tools(Including Deliberatum)Uploaded byluanamdonascimento
- (Texts and Studies in Linguistics and Philosophy 10) Manfred Bierwisch (Auth.), John R. Searle, Ferenc Kiefer, Manfred Bierwisch (Eds.)-Speech Act TheoryUploaded byIvana
- Indexing Data FrameUploaded byluanamdonascimento
- IEEE Intell Sentiment AnalysisUploaded byYoga Prawira
- Maggs-guide to the FederalistsUploaded byluanamdonascimento
- Linz Stepan-Modern Nondemocratic RegimesUploaded byluanamdonascimento
- Diamond-Thinking About Hybrid RegimesUploaded byluanamdonascimento
- Linguistic Structured Sparsity in Text CategorizationUploaded byluanamdonascimento
- Science Disputes in Abortion LawUploaded byluanamdonascimento
- Empirical_Research_on_Deliberative_Democ.docUploaded byluanamdonascimento
- toefl_speaking_rubrics.pdfUploaded byAlexandra Terán
- (Lecture Notes in Social Networks) Fazli Can, Tansel Özyer, Faruk Polat (Eds.)-State of the Art Applications of Social Network Analysis-Springer International Publishing (2014)Uploaded byluanamdonascimento
- (Contemporary Mathematics 503) Marcel de Jeu, Sergei Silvestrov, Christian Skau, Jun Tomiyama (Ed.)-Operator Structures and Dynamical Systems_ July 21-25, 2008 Lorentz Center, Leiden, The NetherlandsUploaded byluanamdonascimento
- r-stat571Uploaded byluanamdonascimento
- ResumoUploaded byluanamdonascimento
- Chapter 02Uploaded byluanamdonascimento
- Importing Data FrameUploaded byluanamdonascimento
- VectorsUploaded byluanamdonascimento
- IndexingUploaded byluanamdonascimento

- BSS Clear Codes NSNUploaded byDenny A Mukhlis
- Director Vice President Engineering in Detroit MI Resume Brian HackettUploaded byBrianHackett
- Piping+Sp3dUploaded byJigy
- unit of work sample 4Uploaded byapi-270277678
- Friday Khutbah - Sincerity_280711Uploaded bySaira Khan
- Macbeth UnitUploaded byJulia Maturo
- Reflection PaperUploaded byRooth Adajet
- SAP 115899 - Correction Report for Subcontractor RequirementsUploaded bybakhele2765
- 8 Key Competencies - For Youthpass in EVSUploaded byBeatrice Mosneagu
- Syntax of MsgBox Function in VBAUploaded byAguest Sukamto
- Manual de mikrotik fulll.docxUploaded byLuis Eduardo Chourio Soto
- Elaine Canning-Lope de Vega's 'Comedias de tema religioso'_ Re-creations and Re-presentations (Monografias A) (2004).pdfUploaded byDenis Kuzmanović
- Barangay.docxUploaded byJuly Grace Reyes Casinillo
- Sri_Krishna_Kathamrita_-_Bindu076.pdfUploaded byjack sparow
- Teknik WritingUploaded byAzri Sha Adelia
- SUBJECT AND VERB INVERSION.pptxUploaded byYohanes Arif
- technical-guide-1.0.pdfUploaded bypatytoo
- THE GOSPEL THE BESORAHUploaded byBesorahSeed
- Power of a pointUploaded byJoseph QiQi Kuan
- Computer JavaUploaded bytanvi kamani
- 2. Bohr Model and QT of Hydrogen AtomUploaded byMudit Singh
- prepositions.pptxUploaded byAsma Azza
- BA in Marketing Communications - June 2010.pdfUploaded byKristofer Soriano
- Social Sin and Fundamental OptionUploaded byKam Ho M. Wong
- cube-mail-0Uploaded bylesmisphantomphan
- IO-os-6Uploaded byNarender Kumar
- Matlab Practice ExercisesUploaded bygeneve1
- Chukwuma Azuonye - The Nwagu Aneke Igbo ScriptUploaded bysector4bk
- Bādhaka1Uploaded bysurinder sangar
- Brstm32_STM32 Platform ProcessorsUploaded bypablocotan

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.