Converting areas to metric 2
You're almost there with creating a function to convert acres to hectares. You need another utility function to deal with getting from square yards to square meters. Then, you can bring everything together to write the overall acres-to-hectares conversion function. Finally, in the next exercise you'll be calculating area conversions in the denominator of a ratio, so you'll need a harmonic acre-to-hectare conversion function.
Free hints: magrittr's raise_to_power()
will be useful here.
The three utility functions from the last exercise (acres_to_sq_yards()
, yards_to_meters()
, and sq_meters_to_hectares()
) are available, as is your get_reciprocal()
from Chapter 2. magrittr
is loaded.
This exercise is part of the course
Introduction to Writing Functions in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Write a function to convert sq. yards to sq. meters
sq_yards_to_sq_meters <- function(sq_yards) {
sq_yards %>%
# Take the square root
___() %>%
# Convert yards to meters
___() %>%
# Square it
___(___)
}