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
290
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
310
From Predictions to Decisions
cjbayesian
1
590
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
140
From Whale Calls to Dark Matter - Competetive Data Science with R and Python
cjbayesian
0
1.4k
Introduction to Likelihood-based methods
cjbayesian
1
790
Implications of uncertainty: Bayesian modelling of aquatic invasive species spread
cjbayesian
0
370
Future Avenues for Open Data
cjbayesian
0
230
Montreal R Users Data Dive - Bike accidents
cjbayesian
0
120
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.5k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
2
130
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
54k
Designing for humans not robots
tammielis
254
26k
Keith and Marios Guide to Fast Websites
keithpitt
411
23k
How to Think Like a Performance Engineer
csswizardry
27
2.1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.2k
How to train your dragon (web standard)
notwaldorf
97
6.3k
Optimizing for Happiness
mojombo
379
70k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
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