<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/a-case-study-in-messy-data-analysis-the-australian-same-sex-marriage-survey/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/12/sex-marriage-survey.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>Last month the Australian people signaled their approval of legalizing same-sex marriage <a rel="nofollow" href="http://www.abc.net.au/news/2017-11-15/same-sex-marriage-results-ssm/9145636" target="_blank">by a 62%:38% margin in a national survey</a>. (On a personal note, I was elated and relieved by the result: my husband and I have discussed eventually retiring to Australia, and with this decision our marriage would be recognized there.) While fears of a surprise Brexit-like electoral backlash proved unfounded, researchers including R user Miles McBain <a rel="nofollow" href="https://medium.com/@miles.mcbain/tidying-the-australian-same-sex-marriage-postal-survey-data-with-r-5d35cea07962" target="_blank">explored the results for correlations to demographic variables</a>. This process wasn't as simple as it might have been though: the Australian Bureau of Statistics <a rel="nofollow" href="https://marriagesurvey.abs.gov.au/results/downloads.html" target="_blank">released the results</a> as a pair of Excel files that violate just about every <a rel="nofollow" href="http://blog.revolutionanalytics.com/2017/11/good-practices-spreadsheets.html" target="_blank">good practice for sharing data in spreadsheets</a>:</p>
<p><a rel="nofollow" href="https://medium.com/@miles.mcbain/tidying-the-australian-same-sex-marriage-postal-survey-data-with-r-5d35cea07962" target="_blank"><img border="0" alt="Survey-results" title="Survey-results" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb09dc35a0970d-800wi"></a></p>
<p>Miles shares the R code he used to extract useful data from this spreadsheet as a <a rel="nofollow" href="https://medium.com/@miles.mcbain/tidying-the-australian-same-sex-marriage-postal-survey-data-with-r-5d35cea07962" target="_blank">blog post that makes a great case study in dealing with messy data</a> using R. The post demonstrates how he used the <code><a rel="nofollow" href="https://www.rdocumentation.org/packages/readxl/versions/1.0.0/topics/read_excel?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank">read_excel</a></code> function (from <a rel="nofollow" href="http://readxl.tidyverse.org/" target="_blank">readxl package</a>) to extract specific sub-tables from the spreadsheet by specifying row and column ranges, and then use the <a rel="nofollow" href="http://dplyr.tidyverse.org/" target="_blank">dplyr package</a> to clean up and merge the data. If you want to explore the data yourself, you can <a rel="nofollow" href="https://github.com/MilesMcBain/tidy_aus_ssm/" target="_blank">find the R code and the source data in this Github repository</a>.</p>
<p>In a follow-up post, Miles combines the <a rel="nofollow" href="https://medium.com/@miles.mcbain/combining-australian-census-data-with-the-same-sex-marriage-postal-survey-in-r-39d9b2082249" target="_blank">same-sex marriage survey data with Australian Census data</a> to explore various demographic relationships. Unlike the US Census data (which is easily accessible in R thanks to the <a rel="nofollow" href="https://mran.microsoft.com/package/tidycensus" target="_blank">tidycensus package</a>), there's no interface package for Australian Census data. (Selected tables are available in the <a rel="nofollow" href="https://mran.microsoft.com/package/Census2016" target="_blank">Census2016 package</a>, however.) Instead, Miles demonstrates how to use R to download and extract data from the the &quot;<a rel="nofollow" href="https://datapacks.censusdata.abs.gov.au/datapacks/" target="_blank">Census DataPacks</a>&quot; (CSV data files and Excel data dictionaries) provided by the Australian Bureau of Statistics.  Yet more data wrangling allows Miles to create summary charts of the responses, such as this chart of proportion voting No by percent of the district population declaring a religious affiliation, broken down by state. As you may expect, those districts with more religious populations voted No at greater rates.</p>
<p><a rel="nofollow" href="https://medium.com/@miles.mcbain/combining-australian-census-data-with-the-same-sex-marriage-postal-survey-in-r-39d9b2082249" target="_blank"><img border="0" alt="Religious-affliliation" title="Religious-affliliation" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b7c939206b970b-800wi"></a></p>
<p>Both of these post provide great examples of working with government data, which is often provided in inconvenient formats with messy structures. Follow the links below for step-by-step guides, including the R code used to extract the data, structure it for analysis, and create useful charts.</p>
<p>Medium (Miles McBain): <a rel="nofollow" href="https://medium.com/@miles.mcbain/tidying-the-australian-same-sex-marriage-postal-survey-data-with-r-5d35cea07962" target="_blank">Tidying the Australian Same Sex Marriage Postal Survey Data with R</a>; <a rel="nofollow" href="https://medium.com/@miles.mcbain/combining-australian-census-data-with-the-same-sex-marriage-postal-survey-in-r-39d9b2082249" target="_blank">Combining Australian Census data with the Same Sex Marriage Postal Survey in R</a></p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.revolutionanalytics.com/2017/12/sex-marriage-survey.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/Xihy0d2jGS0" height="1"></a></div>