Displaying 1 result from an estimated 1 matches for "mergefac3".
Did you mean:
mergefac
2004 Feb 05
0
correction to the previously asked question (about mergin g factors)
...t; f3 <- factor(sample(letters[5:7], 1e4, replace=TRUE))
>
> system.time(for (i in 1:1e2) mf <- mergeFac(f1, f2, f3))
[1] 4.54 0.00 4.73 NA NA
> system.time(for (i in 1:1e2) mf2 <- mergeFac2(f1, f2, f3))
[1] 3.95 0.01 4.11 NA NA
> system.time(for (i in 1:1e2) mf3 <- mergeFac3(f1, f2, f3))
[1] 3.61 0.00 3.76 NA NA
> all(mf == mf2)
[1] TRUE
> all(mf == mf3)
[1] TRUE
First, my attempt at generalizing Spencer's suggestion:
mergeFac <- function(...) {
l <- list(...)
len <- sapply(l, length)
lev <- unique(unlist(lapply(l, levels)))
ans <...