I need to do some descriptive statistic on a dataset. I need to create a table from a dataset that give me, for each level in a factor the mean of another variable.
city mean(age)
1 14
2 15
3 23
4 34
Which is the fastest way to do it in R?
Another thing that I have to do is the same thing, but on 2 dimensions:
mean(age) male female
city
1 12 13
2 15 16
3 21 22
4 34 33
And I wonder if there is also the possibility to apply also other functions like max, min,sum....
Edit: I add a dataset to create examples easier:
data.frame(years=rep(c(12,13,14,15,15,16,34,67,45,78,17,42),2),sex=rep(c("M","F"),12),city=rep(c(1,2,3,4,4,3,2,1),3))