I have df below.
df<-cbind(c("LA", "NY", "Rome"),c(1,1,2),c(0,1,0),c(0,1,2),c(1,3,4))
[city] [c1] [c2] [c3] [sum]
[1,] "LA" "1" "0" "0" "1"
[2,] "NY" "1" "1" "1" "3"
[3,] "Rome" "2" "0" "2" "4"
I want to compare the values in sum column to find the two smallest values .( here 1,3 in increasing order)
then return the corresponding values in city column with the same order.
so what I want in out put is : LA, NY
I can get the rownames ( which I do not want, but I do not know how to get LA, NY:
rownames(df$city[order(df$sum, decreasing = F),][1:2])[1:2]