[R] correction to the previously asked question (about merging factors)

2004-02-05 Thread Svetlana Eden
I have two factors l1, l2, and I'd like to merge them. (Remark: The factors can not be converted to charaters) Function c() does not give me the result I want: l1 = factor(c('', '')) l2 = factor(c('ccc', 'dd')) lMerge = factor(c(l1, l2)) lMerge [1] 1 2 1 2 Levels: 1 2 I'd

Re: [R] correction to the previously asked question (about merging factors)

2004-02-05 Thread Spencer Graves
What about the following: F1 - factor(c(b, a)) F2 - factor(c(c, b)) k1 - length(F1) k2 - length(F2) F12.lvls - unique(c(levels(F1), levels(F2))) F. - factor(rep(F12.lvls[1], k1+k1), levels=F12.lvls) F.[1:k1] - F1 F.[-(1:k1)] - F2 F. [1] b a c b Levels: a b c This saves

Re: [R] correction to the previously asked question (about merging factors)

2004-02-05 Thread Sundar Dorai-Raj
How about simply F1 - factor(c(b, a)) F2 - factor(c(c, b)) F3 - factor(c(levels(F1)[F1], levels(F2)[F2])) -sundar Spencer Graves wrote: What about the following: F1 - factor(c(b, a)) F2 - factor(c(c, b)) k1 - length(F1) k2 - length(F2) F12.lvls - unique(c(levels(F1), levels(F2)))

Re: [R] correction to the previously asked question (about merging factors)

2004-02-05 Thread Peter Dalgaard
Spencer Graves [EMAIL PROTECTED] writes: Sundar: Your solution is not only more elegant than mine, it's also faster, at least with this tiny example: start.time - proc.time() k1 - length(F1) k2 - length(F2) F12.lvls - unique(c(levels(F1), levels(F2))) F. -

Re: [R] correction to the previously asked question (about merging factors)

2004-02-05 Thread Spencer Graves
Thanks, Peter. So Sundar's more elegant solution is equivalent to my initial response to this question -- which shows how much one can lose trying to be too clever. Best Wishes, spencer graves Peter Dalgaard wrote: Spencer Graves [EMAIL PROTECTED] writes: