我有一个包含不同字符串的列,这些字符串沿列重复。我想创建另一个列,它基本上总结字符串的出现次数,并用数字填充此列。这相当于在excel中使用countif函数。
答案 0 :(得分:0)
例如:
s <- c("aaa","aab","aba","abb","bbb")
look_for_what <- "aa"
length(s[grep(look_for_what,s)])
# 2
look_for_what <- "a"
length(s[grep(look_for_what,s)])
# 4