Q:

How to apply model to multiple subsets when some have 0 observations.

I'm looking to forecast using exponential smoothing on one particular field but group it over one or more other fields. I think I have managed to do this, however I need assistance in overcoming the error:
Error in ts(x) : 'ts' object must have one or more observations

I believe this is due to that fact that there may not be any observations for certain group combinations. Is there a way to leave NA's whenever this occurs?
Here is the code I have used to create the exp smoothing. workingexp1 works fine but i get the error on failingexp1 once I introduce further fields to group by. 
library(forecast)
workingexp1 = ave(match$Score, FUN = function(x)fitted(ses(x, alpha = 0.1)))
failingexp1 = ave(match$Score, match$area, match$Student, FUN = function(x)fitted(ses(x, alpha = 0.1)))

Here is the data I'm working with:
school <- c('I','B','B','B','B','I','I','I','I','B','I','I','B','I','B','I','B','B','I','I','B','I','B','I','B','B','I')
Student <- c('S','S','S','O','O','O','O','S','O','S','S','O','S','O','O','S','S','O','S','O','S','O','O','S','S','O','J')
area <- c('A','A','A','A','B','A','B','A','A','A','A','A','A','A','A','A','A','A','A','B','A','A','A','A','A','A','A')
Score <- c(5,2,7,3,9,6,3,7,1,7,3,8,3,4,1,9,4,6,3,8,3,4,1,9,4,6,6)
match <- data.frame(school, Student, area,  Score)

Any help is really appreciated!!!!

A:

You could just modify your function to return NA value whenever the number of elements of a specific combination is too small (it seems that under 4, the exponential doesn't work):
myfun = function(x) {
  if (NROW(x) < 4) {
    res <- NA
  } else {
    res <- fitted(ses(x, alpha = 0.1))
  }
  return(res)
}
failingexp1 = ave(match$Score, match$area, match$Student, FUN = myfun)

