I have a data frame with the following data:
date=strptime(c(20110101,20110102,20110103,20110104,20110105,20110106),'%Y%m%d')
rate1=c(1,2,3,4,5,6)
rate2=c(2,1,3,6,8,4)
rate3=c(4,1,3,6,8,3)
rate4=c(7,8,9,2,1,8)
z=data.frame(date,rate1,rate2,rate3,rate4)
z$max=pmax(rate1,rate2,rate3,rate4)
The pmax function allows me to get the maximum value for that record, but I was wondering how I can get the index of the maximum value for that record.
Where z$max would equal 7,8,9,6,8,8
, I would like to get 5,5,5,3,3,5
Is this possible? I know this seems like something simple but I cannot find the answer anywhere.
See Question&Answers more detail:
os