From http://stackoverflow.com/questions/22198951/calculate-mean-with-a-filter-on-a-columns-values
Applying functions on a filtered column
mean(testd$salary[testd$salary>=25000])
another way is using data table that should be much faster:
testd<-data.table(testd)
testd[salary>25000,mean(salary)]