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
RailsConf 2023
tenderlove
30
1.3k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.7k
The Cult of Friendly URLs
andyhume
79
6.6k
Embracing the Ebb and Flow
colly
88
4.9k
Visualization
eitanlees
149
16k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
190
55k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.7k
Speed Design
sergeychernyshev
32
1.2k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
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