I'm trying to order a data set using the following:
library(dslabs)
data(murders)
pop<- murders$population
pop_min_index <- order(pop)
min(pop_min_index)
When I use this, R presents "pop_min_index" as all the values from the data set, when I just want the first value, i.e. the answer should be "51", where as my result is coming out as "51, 9, 46, 35, 2, 42", etc.
I hadn't even heard of "head", is this the only way to do this question, as we haven't been taught this yet, so just wondering if there is some content missing from the instructions i've been given?
That was exactly my issue. I kept inputting that as:
library(dslabs)
data(murders)
pop<- murders$population
pop_min_index <- order(pop)
pop_min_index[1]