I was just using the aggregate function (see short example below). But how does the aggregate function knows which of my "randomnumb" belongs to which country? Is my list somehow still storing the countries? Or is it just a matter of order?
df <- data.frame(country = c("Canada","Canada","Canada","US","US"),
state = c("state1", "state2", "state3", "state4", "state5"),
randomnumb = c(1:5)
)
list <- list(df$randomnumb)
dfaggregate <- aggregate(list,
by = list(country = df$country),
FUN = mean)