假设我有以下数据集:
keycard=c("a","b","c","b","c","b","c","a","b")
我想计算向量中“ bc”出现的次数。我怎样才能做到这一点?
您可以keycard使用与grepRaw()功能匹配的模式来折叠向量并对其进行处理:
keycard
grepRaw()
s <- paste(keycard, collapse = "") length( grepRaw("bc", s, all = T) ) #[1] 3