Skip to content
Course Notes: Intermediate R
Course Notes
Use this workspace to take notes, store code snippets, or build your own interactive cheatsheet! The datasets used in this course are available in the datasets folder.
# initialize speed
speed <- 50
# while loop
while (speed > 30) {
print("Slow down!")
speed <- speed - 7
}
# Initialize the speed variable
speed <- 64
# Extend/adapt the while loop
while (speed > 30) {
print(paste("Your speed is",speed))
if (speed > 48) {
print ("Slow down big time!")
speed <- speed- 11
} else {
print("Slow down!")
speed <- speed- 6
}
}
speed <- 88
while (speed > 30) {
print(paste("Your speed is", speed))
# Break the while loop when speed exceeds 80
if (speed > 80 ) {
break
}
if (speed > 48) {
print("Slow down big time!")
speed <- speed - 11
} else {
print("Slow down!")
speed <- speed - 6
}
}
# Initialize i as 1
i <- 1
# Code the while loop
while (i <= 10) {
print(3 * i)
if ( (3 * i) %% 8 == 0) {
break
}
i <- i + 1
}
# Import any packages you want to use here
Take Notes
Add notes here about the concepts you've learned and code cells with code you want to keep.
Add your notes here
# Add your code snippets here