假设我有一张桌子
> tab <- table(c("www.a.com","a.com","a.com","www.b.com"))
> tab
a.com www.a.com www.b.com
2 1 1
我想合并"www.a.com"
和"a.com"
的条目以获取
a.com b.com
3 1
我有
> fqdn.normalization.regexp <- "^ww*[0-9]*\\."
> normalize.fqdn <- function (domain) sub(fqdn.normalization.regexp,"",domain)
> normalize.fqdn(names(tab))
[1] "a.com" "a.com" "b.com"
问题是,如何将tab
值转换为我需要的值?
答案 0 :(得分:0)
> names(tab) <- normalize.fqdn(names(tab))
> tapply(tab, names(tab), sum)
a.com b.com
3 1