Not strictly dplyr
but I consider this to be rather easy to read (at least not many nested parens). Also: My minmonth
function is handy for reuse some other time and it is easily translated to input in a non-English language:
dat <- read.table(text = "ID V1 V2
A 2 June
B 3 May
A 2 January
F 4 December", header = TRUE)
minmonth <- function(m){
months <- c(January = 1, February = 2, March = 3, # easily translated to
April = 4, May = 5, June = 6, July = 7, # other languages
August = 8, September = 9, October = 10,
November = 11, December = 12)
m <- months[m] # no static typing in R
smallest <- min(m)
return(names(months)[smallest])
}
dat$V3 <- ave(dat$V2, dat$ID, FUN = minmonth)