Вы можете использовать aggregate
:
aggregate(cbind(days=x$Precipitation > 0), as.list(x[c("Location", "Year", "Month")]), sum)
# Location Year Month days
#1 A 2008 1 2
Данные:
x <- structure(list(Location = structure(c(1L, 1L, 1L, 1L), .Label = "A", class = "factor"),
Year = c(2008L, 2008L, 2008L, 2008L), Month = c(1L, 1L, 1L,
1L), Day = 1:4, Precipitation = c(0, 8.32, 4.89, 0)), class = "data.frame", row.names = c(NA, -4L))