In your for loop, you don't actually use the individual values that you're looping through, you compare against the whole year
vector every time. Using the individual values fixes your immediate problem:
g<-function(year){
lis<-vector()
for( i in year){
if(i == 2013){lis<-append(lis,1:12)}
if(i == 2012){lis<-append(lis,13:24)}
if(i == 2011){lis<-append(lis,24:36)}
}
return(lis)
}
Or you could do the same thing without a for loop:
g2 <-function(year){
lis<-vector()
if (2013 %in% year) {lis <- append(lis, 1:12)}
if (2012 %in% year) {lis <- append(lis, 13:24)}
if (2011 %in% year) {lis <- append(lis, 24:36)}
return(lis)
}