Say I have a dataframe
with 250 rows and 1000 columns. I want to find the 10 maximum values and the 10 minimum values, which I can easily to with tail
and head
function applying on the vectorised dataframe
.
But how do I now which columns and rows the highest values are in?
Example:
df <- data.frame(c("house1", "house2", "house3"), c(2006, 2007, 2008), c(0.3, 0.5, 0.1), c(0.9, 0.4, 0.01))
colnames(df) <- c("house.num", "year", "data1", "data2")
> df
house.num year data1 data2
1 house1 2006 0.3 0.90
2 house2 2007 0.5 0.40
3 house3 2008 0.1 0.01
I would like to have the 3 maximum values of the data1 and data2 columns and the information in which row and column these values are, so I know which house, which year and which datatype match the best.