0

假设我有一张桌子

> 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值转换为我需要的值?

4

1 回答 1

0
> names(tab) <- normalize.fqdn(names(tab))
> tapply(tab, names(tab), sum)
a.com b.com 
    3     1 
于 2013-06-07T18:11:40.507 回答