Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Quiz
5. Exercise 5

Instruction

Nicely done!

Each data frame contains an additional column named distance_covered_km that, as the name suggests, tells us how many kilometers the company's shipping truck traveled between the previous destination and the current one. For example, Lyon was company_a's eighth destination. Before Lyon, the truck was in Nantes. The company's truck traveled 685 km between these two cities.

city country quantity destination_number distance_covered_km production_center
1 Prague Czech Republic 200000 0 0 Y
2 Antwerp Belgium 200000 6 55 Y
3 Madrid Spain 200000 -1 0 Y
4 Nantes France 30000 7 722 N
5 Lyon France 25000 8 685 N
6 Milan Italy 55000 9 447 N
7 Salzburg Austria 40000 2 430 N
8 Brno Czech Republic 20000 1 217 N
9 Dresden Germany 10000 3 612 N
10 Frankfurt Germany 50000 4 460 N
11 Brussels Belgium 70000 5 399 N

Exercise

Display the largest distance that was covered between two cities among companies a, b, and c. Return the result as a vector (that is, use sapply()).

Stuck? Here's a hint!

You should use an anonymous function here that takes one argument, x, and returns the max element of the distance_covered_km column. Type:

sapply(companies, 
  function(x){ 
    return(max(x$distance_covered_km))
  }
)