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
260
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
180
From Predictions to Decisions
cjbayesian
1
490
NIPS 2017 Summary
cjbayesian
1
1.5k
Validation des prévisions écologiques utilisant VMAPP: Validation métrique appliquée à des prévisions probabilistes
cjbayesian
1
110
From Whale Calls to Dark Matter - Competetive Data Science with R and Python
cjbayesian
0
1.4k
Introduction to Likelihood-based methods
cjbayesian
1
570
Implications of uncertainty: Bayesian modelling of aquatic invasive species spread
cjbayesian
0
260
Future Avenues for Open Data
cjbayesian
0
160
Montreal R Users Data Dive - Bike accidents
cjbayesian
0
110
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
354
18k
For a Future-Friendly Web
brad_frost
171
8.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
18
1.7k
Practical Orchestrator
shlominoach
181
9.7k
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
Automating Front-end Workflow
addyosmani
1355
200k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
15
1.4k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
658
120k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
19
1.9k
Fantastic passwords and where to find them - at NoRuKo
philnash
36
2.5k
A Tale of Four Properties
chriscoyier
150
22k
Done Done
chrislema
178
15k
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