I'm new to R and the Forum, so let me know if you need any more Information in order to help me with the issue. Big Thanks in advance for any help!
I'm currently stuck with a problem, which in theory should be easy to solve with the .drop command, which for some reason though is not working for me.
I want to create an object, which includes the opposition's "yes" and "no" votes regarding a certain vote in parliament. Now when the frequency counts are >0, it includes frequencies for both "yes" and "no". However, if the opposition voted unitary on an issue (e.g 200 yes votes, 0 no votes), the 0 frequencies is dropped for some reason.
library(foreign)
library(tidyverse)
library(readstata13)
library(tibbletime)
library(lubridate)
library(car)
BTFULLOPPSUM <- BTFULLD %>% dplyr::filter(Opposition == 1) %>% dplyr::group_by(vote_id, vote_beh, .drop = FALSE) %>%
dplyr::summarise(number = n())
#BTFULLOPPSUM is the new object. BTFULLD the dataframe
That's the result.
number
vote_id Y/N number
1 9001 0 226
2 9002 0 227
3 9003 0 213
4 9004 0 16
5 9004 1 196
1 == Yes, 0 == NO
This is what I would like:
1 9001 0 226
2 9001 1 0
3 9002 0 227
4 9002 1 0
vote_beh is the voting decesion, so either Yes (1) or no (0). I hope that's sufficient, because the issue already starts with the vote 9001, as non of the opposition parties voted with Yes. (Opposition parties in this vote were the CDU/CSU for example).
This is the dput of a small part of the important variables for the vote_id 9001. It looks much more confusing to me, but maybe you can work properly with that.
structure(list(vote_id = c(9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001, 9001,
9001, 9001, 9001), vote_beh = c(0, 0, 1, 0, 1, 1, 1, 0, 1, 1,
0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0,
0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1,
1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0,
0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1,
0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0,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