Difference between revisions of "File:Ohio Election Results Nov 2012.csv"
From Testiwiki
({{study}} Results of presidential election in Ohio, Nov 7, 2012 (including all other elections on the same day). Data was obtained from [http://www2.sos.state.oh.us/pls/enrpublic/f?p=212:27:0::NO:::] resulting in an Excel file Reports.xls, which was rena) |
(data management done, ovariable saved, no analyses) |
||
Line 1: | Line 1: | ||
− | {{study}} | + | [[Category:US presidential election 2012]] |
+ | {{study|moderator=Jouni}} | ||
Results of presidential election in Ohio, Nov 7, 2012 (including all other elections on the same day). | Results of presidential election in Ohio, Nov 7, 2012 (including all other elections on the same day). | ||
Data was obtained from | Data was obtained from | ||
[http://www2.sos.state.oh.us/pls/enrpublic/f?p=212:27:0::NO:::] resulting in an Excel file Reports.xls, which was renamed and saved as csv without other editing. | [http://www2.sos.state.oh.us/pls/enrpublic/f?p=212:27:0::NO:::] resulting in an Excel file Reports.xls, which was renamed and saved as csv without other editing. | ||
− | [[ | + | |
+ | Default run: SSDDvuDfVDKOhlkO [http://en.opasnet.org/en-opwiki/index.php/Special:R-tools?id=SSDDvuDfVDKOhlkO] | ||
+ | |||
+ | <rcode graphics="1"> | ||
+ | library(OpasnetUtils) | ||
+ | library(xtable) | ||
+ | library(ggplot2) | ||
+ | library(reshape2) | ||
+ | |||
+ | #Fetch the election data from Ohio | ||
+ | |||
+ | data <- opasnet.csv("d/df/Ohio_Election_Results_Nov_2012.csv", sep = ",", skip = 3) | ||
+ | datacol <- t(opasnet.csv("d/df/Ohio_Election_Results_Nov_2012.csv", sep = ",", skip = 2, nrow = 1))[ , 1] | ||
+ | colnames(data) <- datacol | ||
+ | data <- data[data["Media Market"] != "TOTALS:", ] # Remove the total row | ||
+ | |||
+ | # Elections contains the names of different elections held at the same time. | ||
+ | |||
+ | elections <- t(opasnet.csv("d/df/Ohio_Election_Results_Nov_2012.csv", sep = ",", skip = 1, nrow = 1))[ , 1] | ||
+ | |||
+ | # Copy elections to subsequent rows until a new election begins. | ||
+ | temp <- "" | ||
+ | for(i in 1:length(elections)) { | ||
+ | elections[i] <- ifelse(is.na(elections[i]), temp, elections[i]) | ||
+ | temp <- elections[i] | ||
+ | } | ||
+ | |||
+ | # Melt data into long format. | ||
+ | |||
+ | data <- melt(data, id.vars = c("County", "Region", "Media Market", "REGISTERED_VOTERS"), variable.name = "Candidate", value.name = "Result", na.rm = TRUE) | ||
+ | |||
+ | # Bring in the elections. | ||
+ | data <- merge(data, data.frame(Candidate = datacol, Election = elections)) | ||
+ | |||
+ | election.ohio.2012 <- new("ovariable", | ||
+ | name = "election.ohio.2012", | ||
+ | data = data | ||
+ | ) | ||
+ | |||
+ | objects.put(election.ohio.2012) | ||
+ | |||
+ | cat("Object election.ohio.2012 saved successfully. \n") | ||
+ | |||
+ | </rcode> |
Latest revision as of 17:43, 7 November 2012
This page is a study.
The page identifier is Op_en5849 |
---|
Moderator:Jouni (see all) |
Give your opinion to the peer rating of the content of this page. |
Upload data
|
Results of presidential election in Ohio, Nov 7, 2012 (including all other elections on the same day). Data was obtained from [1] resulting in an Excel file Reports.xls, which was renamed and saved as csv without other editing.
Default run: SSDDvuDfVDKOhlkO [2]
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Dimensions | User | Comment | |
---|---|---|---|---|
current | 12:40, 7 November 2012 | (61 KB) | Jouni (talk | contribs) | {{study}} Results of presidential election in Ohio, Nov 7, 2012 (including all other elections on the same day). Data was obtained from [http://www2.sos.state.oh.us/pls/enrpublic/f?p=212:27:0::NO:::] resulting in an Excel file Reports.xls, which was rena |
- You cannot overwrite this file.
File usage
There are no pages that link to this file.