This a simplified display of my data:
I am interested in how Germany rankings on each of the variables, population, area, Literacy rate_male, etc.
How can I do it?
This a simplified display of my data:
I am interested in how Germany rankings on each of the variables, population, area, Literacy rate_male, etc.
How can I do it?
You seem to have a dataframe with one variable the name of a country and the others numeric. To get an easily reproducible example with a similar structure: start with the built-in dataframe mtcars
(evaluate ?mtcars
for details) and then run the following two commands:
mtcars$make <- row.names(mtcars)
row.names(mtcars) <- NULL
Say you wanted to get the ranks of Datsun 710
(the third row of the dataframe). Then you could use:
ranks <- apply(mtcars[,names(mtcars) != "make"],2,function(v) rank(v)[which(mtcars$make == "Datsun 710")])
Resulting variable looks like:
> ranks
mpg cyl disp hp drat wt qsec vs am gear carb
24.5 6.0 6.0 7.0 20.0 7.0 23.0 25.5 26.0 21.5 4.0
In your case, something along the lines of
ranks <- apply(df[,names(df) != "location_name"],2,function(v) rank(v)[which(df$location_name == "Germany")])
should work.