I have a table of locations and values for Precipitation of each month.
I need to add a new column with name of the month that has the maximum Precipitation for each location.
I tried to do that:
cbind(rainfall, max_month = apply(rainfall[,3:11],1,which.max))
but I'm getting only the number of the column and I need the name of the column. I got this :
[1] 5 5 5 5 5 5 5 5 4 4 5 5 5 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
[59] 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 5 5 4 5 5 5 5 5 5 5 5 5 5 5 5
[117] 5 5 5 5 5 5 5 5 5 6 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4
I tried to add the names function and the colnames function' but both of them didnt help.
names(apply(rainfall[,3:11],1,(which.max)))
Thanks