Not sure how to domesticate ddply
here by summarising my gender counts for countries. I have this data frame
df <- data.frame(country = c("Italy", "Germany", "Italy", "USA","Poland"),
gender = c("male", "female", "male", "female", "female"))
And I want a dataframe where each row details how many males and females each country has. Yet
ddply(df,~country,table)
country female male
1 Germany 1 0
2 Germany 0 0
3 Germany 0 0
4 Germany 0 0
5 Italy 0 0
6 Italy 0 2
7 Italy 0 0
8 Italy 0 0
9 Poland 0 0
10 Poland 0 0
11 Poland 1 0
12 Poland 0 0
13 USA 0 0
14 USA 0 0
15 USA 0 0
16 USA 1 0
although it produces the desired result it also adds three extra line for each group. Why?