Count the frequency of strings in a dataframe R
问题 I am wanting to count the frequencies of certain strings within a dataframe. strings <- c("pi","pie","piece","pin","pinned","post") df <- as.data.frame(strings) I would then like to count the frequency of the strings: counts <- c("pi", "in", "pie", "ie") To give me something like: string freq pi 5 in 2 pie 2 ie 2 I have experimented with grepl and table but I don't see how I can specify the strings I want to search for are. 回答1: You can use sapply() to go the counts and match every item in