[r] Count number of rows matching a criteria