Skip to content

Instantly share code, notes, and snippets.

Created October 27, 2015 15:35
Show Gist options
  • Save anonymous/6c5a6db9f83bd4ae6197 to your computer and use it in GitHub Desktop.
Save anonymous/6c5a6db9f83bd4ae6197 to your computer and use it in GitHub Desktop.
#look at vote share for each state and how Fox News affects it
vote.share.per.state <- rep(NA, 51) # initialize a vector place holder
## state names which the loop will iterate through
st.names <- unique(Fox$state)
## add labels for easy interpretation later on
names(vote.share.per.state) <- as.character(st.names)
## loop across 50 states plus DC
for (i in 1:51){
## subset the ith state
state.data <- subset(Fox, subset = (state == state.name[i]))
vote.share.per.state[i] <- mean(state.data$gopvoteshare2000)
}
vote.share.per.state <- rep(NA, 51) # initialize a vector place holder
## state names which the loop will iterate through
st.names <- unique(Fox$state)
## add labels for easy interpretation later on
names(vote.share.per.state) <- as.character(st.names)
## loop across 50 states plus DC
for (i in 1:51){
## subset the ith state
state.data <- subset(Fox, subset = (state == state.name[i]))
vote.share[i] <- mean(state.data$gopvoteshare1996)
}
vote.share.per.state <- rep(NA, 51) # initialize a vector place holder
## state names which the loop will iterate through
st.names <- unique(Fox$state)
## add labels for easy interpretation later on
names(vote.share.per.state) <- as.character(st.names)
## loop across 50 states plus DC
for (i in 1:51){
## subset the ith state
state.data <- subset(Fox, subset = (state == state.name[i]))
vote.share[i] <- mean(state.data$gopvoteshare1992)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment