forked from INFO-498F/lecture-6-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise1.R
More file actions
29 lines (20 loc) · 855 Bytes
/
exercise1.R
File metadata and controls
29 lines (20 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
### Exercise 1 ###
# Create a vector of everything you ate for breakfast
breakfast <- c('Oatmeal','water','cherry flavoured greek yoghurt')
# Create a vector of everything you ate for lunch
lunch <- ('Pizza')
# Create a list "meals" that has contains your breakfast and lunch
meals <- list(breakfast, lunch)
# Add a "dinner" index to your "meals" list that has what you plan to eat for dinner
meals$dinner <- c('pulled pork', 'sliders', 'ginger ale')
# Extract your 'dinner' element from your list and save it in a vector called 'dinner'
dinner <- meals[['dinner']]
### Bonus ###
# Create a list that has the number of items you ate for each meal
items <- lapply(meals, length)
# Write a function that adds pizza to every meal
add_pizza <- function(x) {
x <- c(x, 'pizza')
}
# Add pizza to every meal!
added_pizza <- lapply(meals, add_pizza)