r: coding dummy variables based-on max value for each month
问题 I want to code a new variable called df$dummy based-on the max value in df$var1 for each df$month , where the value will be 1 for the max value and 0 for every other value. See reproducible data set: df<- data.frame(date= seq.Date(from = as.Date('2017-01-01'), by= 7, length.out = 20), var1= rnorm(20, 5, 3)) df$month<- as.numeric(strftime(df$date, "%m")) I'm having trouble conceptualizing the conditions for the function. In Excel I would just use the maxif function and specific my criteria. My