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
270
From Predictions to Decisions
cjbayesian
1
550
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
130
From Whale Calls to Dark Matter - Competetive Data Science with R and Python
cjbayesian
0
1.4k
Introduction to Likelihood-based methods
cjbayesian
1
710
Implications of uncertainty: Bayesian modelling of aquatic invasive species spread
cjbayesian
0
320
Future Avenues for Open Data
cjbayesian
0
190
Montreal R Users Data Dive - Bike accidents
cjbayesian
0
120
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
47
7.3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
30
4.6k
Building a Scalable Design System with Sketch
lauravandoore
461
33k
Statistics for Hackers
jakevdp
797
220k
Designing Experiences People Love
moore
140
23k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
640
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.1k
4 Signs Your Business is Dying
shpigford
182
22k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
A designer walks into a library…
pauljervisheath
205
24k
Building an army of robots
kneath
303
45k
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