I’m doing part 6 of this guided project and I’ve created the vectors and named them and that seems to work okay.
countries <- covid_top_10$Country_Region
tested_cases <- covid_top_10$tested
positive_cases <- covid_top_10$positive
active_cases <- covid_top_10$active
hospitalized_cases <- covid_top_10$hospitalized
names(tested_cases) <- countries
names(positive_cases) <- countries
names(active_cases) <- countries
names(hospitalized_cases) <- countries
The next question in the section has confused me.
3. Identify the top three positive against tested cases.
Divide the vector positive_cases by the vector tested_cases using the operator /.
Identify the top three ratio.
Store the result as the named vector, positive_tested_top_3, where each country name is associated with its ratio.
I’ve had to create an interim vector before sorting and isolating the head(3).
sort(decreasing = TRUE) %>%
head(3)
positive_tested_top_3
This doesn’t seem very elegant but does seem to work. Is there a better way? thanks in advance.