I have a column in a dataframe that looks like this:
df = data.frame(c("A","B","A,B","","A,C,D"))
What I would like to do is count the frequency of each individual term and return a dataframe that looks something like this:
A 3
B 2
C 1
I'm familiar with the various methods for splitting these strings into columns in my dataframe such as cSplit, read.table, etc., but that's not ideal since I have hundreds of distinct values that I need to count.
Thank you!
Simple solution form David. Thanks!
table(unlist(strsplit(c("A","B","A,B","","A,C,D"), ",")))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.