I want to reshape my data but couldn't figure out how because it's not exactly from wide to long.
Here's a sample of my data, population by single year of age and by sex
data <- structure(list(`2010 - Both Sexes - 0` = 163753, `2010 - Male - 0` = 83878, `2010 - Female - 0` = 79875, `2011 - Both Sexes - 0` = 161923,
`2011 - Male - 0` = 83134, `2011 - Female - 0` = 78789, `2010 - Both Sexes - 1` = 163043,
`2010 - Male - 1` = 83174, `2010 - Female - 1` = 79869, `2011 - Both Sexes - 1` = 163342,
`2011 - Male - 1` = 83472, `2011 - Female - 1` = 79870), row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame"))
My desired dataset would look like the following:
age 2010 - Both Sexes 2010 - Male 2010 - Female 2011 - Both Sexes 2011 - Male 2011 - Female ...
0
1
...
Can anyone help? Thanks.
age
come from? Not all columns have- 0
or- 1
. 2. That's looks like an awful (untidy) output format. Is that really want you want? – Maurits Eversage
would be a new column, columns that don't have 0 or 1 are the total population. I just deleted them. – Eric Wang