1. Learn
  2. /
  3. Courses
  4. /
  5. Data Science R Basics

Exercise

Vectorized operations

Previously we created this data frame:

temp <- c(35, 88, 42, 84, 81, 30)
city <- c("Beijing", "Lagos", "Paris", "Rio de Janeiro", "San Juan", "Toronto")
city_temps <- data.frame(name = city, temperature = temp)

Instructions

100 XP

We are interested in specifying Celsius instead of Fahrenheit. Remember that to convert from Fahrenheit to Celsius we use \(C = 5/9 \times (F-32)\).

  • Use vector arithmetic to convert temp to Celsius
  • Create a data frame called city_temps with the city names and temperatures in Celsius.