不過 grepl 是回傳 TRUE 或 FALSE,
而要計算文字在句中出現次數的話,
就要使用 stringr 套件中的 str_count,
其回傳值為出現次數(數值),
下面範例可以試試看,
會比較好理解。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grepl("我", "我我我我我") | |
library(stringr) | |
str_count("我我我我我", "我") | |
str_count(c("我我我我我", "我我"), "我") |
沒有留言:
張貼留言