Print Maximum of column of data frame with the row name of item

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Print Maximum of column of data frame with the row name of item

QuestionCookie
Hello!

I'm doing this exercise and I don't know how to solve it.
I have this data frame, which I had to create with a matrix...

A <- matrix(c(357,544,42,84,41,80622,66028,16804,8474,8081,5.4,9.9,5.3,4.3,4.2),nrow=5, ncol=3)
colnames(A) <- c("Area", "Population", "Unemployment Rate")
rownames(A) <- c("Germany","France","Netherlands","Austria","Switzerland")

#b)
A <- as.data.frame(A)
PerQkm <- A$`Population`/A$`Area`
A <- cbind(A, PerQkm)

#c)
maximum <- sapply(A,max)
minimum <- sapply(A,min)


Now, the question is, I have to print out the maximum of each column, but I have to print out the countries to each maximum, too, which are the row names. Is there any way to do it?
I tried so many options with rownames, row.names, names etc...

Thank you!!!