Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Loops and Conditionals in R - short
Search
Corey Chivers
March 22, 2013
0
300
Loops and Conditionals in R - short
Corey Chivers
March 22, 2013
Tweet
Share
More Decks by Corey Chivers
See All by Corey Chivers
Germination Project Data Science at Penn Medicine
cjbayesian
1
320
From Predictions to Decisions
cjbayesian
1
610
NIPS 2017 Summary
cjbayesian
1
1.6k
Validation des prévisions écologiques utilisant VMAPP: Validation métrique appliquée à des prévisions probabilistes
cjbayesian
1
150
From Whale Calls to Dark Matter - Competetive Data Science with R and Python
cjbayesian
0
1.4k
Introduction to Likelihood-based methods
cjbayesian
1
830
Implications of uncertainty: Bayesian modelling of aquatic invasive species spread
cjbayesian
0
370
Future Avenues for Open Data
cjbayesian
0
250
Montreal R Users Data Dive - Bike accidents
cjbayesian
0
130
Featured
See All Featured
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
250
Unsuck your backbone
ammeep
671
58k
Amusing Abliteration
ianozsvald
0
87
My Coaching Mixtape
mlcsv
0
37
A better future with KSS
kneath
240
18k
WENDY [Excerpt]
tessaabrams
9
35k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
160
SEO for Brand Visibility & Recognition
aleyda
0
4.2k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
130
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
Transcript
•R is a full fledged programming language. It can do
loops and conditionals. i <- runif(1,0,100) if(i <= 50) { print(‘i is pretty small’) } Control Structures for(i in 1:100) { print(i) }
•A loop will be executed over and over. Control Structures
fruits<- c('apple','orange','banana','pear') for(fruit in fruits) { print(fruit) }
•Combining loops with conditionals can be very powerful. Control Structures
fruits<- c('apple','orange','banana','pear') for(fruit in fruits) { print(fruit) if(fruit == 'banana') print(paste(fruit,'rama!',sep='') }
Challenge 1) Print out all the numbers between 1 and
100, but if the number is a multiple of 3, print ‘fizz’ instead. 2) Extend your code so that for multiples of 5, it prints out ‘buzz’. HINT: To get the remainder of integer division, use %%. Ex: 4 9%%5