I have some data that I am trying to count and pivot_wider. The data looks like:
1 second
2 c("fourth", "fourth", "fourth", "fourth")
3 c("second", "second")
4 c("second", "second")
5 second
6 c("second", "third", "second")
7 fourth
8 fourth
9 c("third", "fourth")
10 c("fourth", "fourth", "fourth", "fourth", "fourth", "fourth")
I am trying to get the data to look like:
first second third fourth
1 1
2 4
3 2
4 2
5 1
6 2 1
7 1
8 1
9 1 1
10 6
Where the numbers are just counts of the number of times the word appears in the column
Data
d1 <- structure(list(quarterMentioned = list("second", c("fourth",
"fourth", "fourth", "fourth"), c("second", "second"), c("second",
"second"), "second", c("second", "third", "second"), "fourth",
"fourth", c("third", "fourth"), c("fourth", "fourth", "fourth",
"fourth", "fourth", "fourth"))), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))