Hello
Please run this code 5 times
Hello
Please run this code 5 times
Hello
Please run this code 5 times
Hello
Please run this code 5 times
Hello
Please run this code 5 times
Week 7, Part 1
DSAN Summer Bootcamp 2024
Georgetown University
In case you haven’t heard this term…
Control flow is just the idea of: how do we control the flow of program execution (individual statements or blocks) in [programming language]
Python uses Indentation →→
R uses curly braces {}
[1] "Hello"
[1] "Please run this code 5 times"
[1] "Hello"
[1] "Please run this code 5 times"
[1] "Hello"
[1] "Please run this code 5 times"
[1] "Hello"
[1] "Please run this code 5 times"
[1] "Hello"
[1] "Please run this code 5 times"
library(lubridate)
cur_time <- Sys.time()
writeLines(paste0(
"The current time is ",
hour(cur_time),":",
minute(cur_time)
))The current time is 17:32
if (hour(cur_time) < 12) {
print("Good morning!")
} else if (hour(cur_time) < 18) {
print("Good afternoon!")
} else {
print("Good evening!")
}[1] "Good afternoon!"
(We’ll learn about lubridate soon!)
C)for (i in 1:nrow(driver_df)) {
driver_df[i, 'mph'] <- driver_df[i, 'miles'] / driver_df[i, 'hrs']
}
driver_df| miles | hrs | mph |
|---|---|---|
| 11 | 2 | 5.50000 |
| 52 | 3 | 17.33333 |
| 13 | 5 | 2.60000 |
deflambda:)Positional arguments are required (function call will produce error if any positional argument is missing)
func(arg)apply() functions: sapply() for vectors; lapply() for lists; apply() for matrices (requires specifying axis: columns or rows)2024 DSAN Bootcamp W07-1: Control Flow