Q:

Understanding the output of table()

I have this dataframe
df <- data.frame(country = c("Italy", "Germany", "Italy", "USA","Poland"),
                 gender = c("male", "female", "female", "female", NA))

which I want to aggregate in a different dataframe which summarises the number of female and male in each column such as 
df_result <- data.frame(country = c("Germany","Italy","Poland","USA","<NA>"),
                        female = c(1,1,0,1,0),
                        male = c(0,1,0,0,0),
                        "NA" = c(0,0,1,0,0))

yet
as.data.frame(table(df, useNA = "always"))
   country gender Freq
1  Germany female    1
2    Italy female    1
3   Poland female    0
4      USA female    1
5     <NA> female    0
6  Germany   male    0
7    Italy   male    1
8   Poland   male    0
9      USA   male    0
10    <NA>   male    0
11 Germany   <NA>    0
12   Italy   <NA>    0
13  Poland   <NA>    1
14     USA   <NA>    0
15    <NA>   <NA>    0

A:

 df$gender <- as.character(df$gender)
 df$gender[is.na(df$gender)] <- "NA." 
 as.data.frame.matrix(table(df))
 #       female male NA. 
 #Germany      1    0   0
 #Italy        1    1   0
 #Poland       0    0   1
 #USA          1    0   0

