I am working with a dataframe containing bills tabled in parliament and including, amongst other variables, the names of all MPs sponsoring the respective bill. The number of MPs supporting a given bill ranges from half a dozen to 450, meaning that there are a lot of NAs included, which are giving me a hard time. I want to count the frequencies of all unique names of MPs in the columns "MP1" to "MP448". For the sake of simplicity, let's work with only 3 different name columns:
df <- data.frame(cbind(Bill = c("housing" , "education" , "agriculture" , "drugs"),
MP1 = c("Bob" , "Edgar" , "Chris" , "Bob"), MP2 = c("Susan" , "Julia", "Reece", ""),
MP3 = c("" , "" , "Julia", "")))
> df
Bill MP1 MP2 MP3
1 housing Bob Susan NA
2 education Edgar Julia NA
3 agriculture Chris Reece Julia
4 drugs Bob NA NA
I want to count the frequencies of the different unique values of the columns containing the names of the MPs. The desired output would be something like this:
> frequencies
Name Count
Bob 2
Edgar 1
Chris 1
Susan 1
Julia 2
Reece 1
Thank you ever so much for your help!