Question

Suppose I have a table

> 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 

I want to merge the entries for "www.a.com" and "a.com" to get

    a.com  b.com 
        3      1

I have

> 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"

The question is, how do I convert tab values to what I need?

Was it helpful?

Solution

> names(tab) <- normalize.fqdn(names(tab))
> tapply(tab, names(tab), sum)
a.com b.com 
    3     1 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top