<- c(30, 40, 10, 20) prices
8 Example solutions
Lemo-nam
8.1 Aurlandsdalen
My travel goal is Aurlandsdalen. It’s on the west coast of Norway, a beautiful valley with rivers, waterfalls and mountains. I was there once some years ago, and it was wonderful. Unfortunately, we didn’t walk the whole valley back then. It’s about 57 km, and you can walk from cabin to cabin.
Price: about 5000 kroner
8.2 Lemonade sales
30*3+40*1+10*4+20*0
[1] 170
1]*3+prices[2]*1+prices[3]*4+prices[4]*0 prices[
[1] 170
sum(prices)
[1] 100
<- c("Fruity stuff", "Exotic mango", "Cheap crap", "Minty greens") names
library(tidyverse)
<- tibble(prices, names) lemonades
lemonades
# A tibble: 4 × 2
prices names
<dbl> <chr>
1 30 Fruity stuff
2 40 Exotic mango
3 10 Cheap crap
4 20 Minty greens
# My favorite lemonade is on row 2
# Checking the independent vectors:
class(prices)
[1] "numeric"
class(names)
[1] "character"
# Checking the variables in the dataset:
class(lemonades$prices)
[1] "numeric"
class(lemonades$names)
[1] "character"
# prices is numeric and names is character. Since the dataset contains two variables of different types, we could not have made it into a matrix. Matrices require all variables to be of the same type.
<- c(49, 21, 59, 44) customers
<- lemonades %>%
lemonades mutate(customers = customers)
sum(lemonades$prices*lemonades$customers)
[1] 3780
One more stand should do it.
::include_graphics("./aurland.jpg") knitr