我有一个数据集如下:
interests<-data.frame(interests=c("A mentor/teacher,Friendship",
"A play partner,Princess by day slut by night,Friendship,A sub,A slave",
"A relationship,A play partner,Friendship,Events",
"Not Defined"))
所以数据集如下:
interests
<fctr>
A mentor/teacher,Friendship
A play partner,Princess by day slut by night,Friendship,A sub,A slave
A relationship,A play partner,Friendship,Events
Not Defined
我需要知道, 每个字词在数据集中重复多少次?
例如&#34;友谊&#34; 重复 3 次,但&#34; A play伴侣&#34; 已经重新计算 2 次,其余的重复一次。
我见过像this这样的类似问题,但问题是条款的长度不同。
答案 0 :(得分:3)
table(unlist(strsplit(as.character(interests$interests), split="\\W")))
或者,因为你似乎认为“玩伴”是一个单词:
table(unlist(strsplit(as.character(interests$interests), split=",")))