3
how do I select the 5 highest values (km in this example) in a data set? I only know the function which() and max(), but they give only the greatest of all, not the biggest 5 for example.
dados <- data.frame(nome = letters[1:11],
km = c(10,220,320,310,506,490,120,15,16,67,506))
max(dados$km)
which(dados$km == max(dados$km))
Only detail with the data.table syntax: no commas needed at the end:
dados[order(km, decreasing = TRUE)][1:5]
works the same.– Carlos Eduardo Lagosta
Great! I’ll edit it!
– Josiane Souza