Re: [R] test for nested factors

2007-06-05 Thread J. R. M. Hosking
Tim Bergsma wrote: Is there a conventional way to test for nested factors? I.e., if 'a' and 'b' are lists of same-length factors, does each level specified by 'a' correspond to exactly one level specified by 'b'? all( tapply(b, a, function(x) length(unique(x))==1 )) J. R. M. Hosking

[R] test for nested factors

2007-06-04 Thread Tim Bergsma
Is there a conventional way to test for nested factors? I.e., if 'a' and 'b' are lists of same-length factors, does each level specified by 'a' correspond to exactly one level specified by 'b'? The function below seems to suffice, but I'd be happy to know of a more succinct solution, if it

Re: [R] test for nested factors

2007-06-04 Thread hadley wickham
On 6/4/07, Tim Bergsma [EMAIL PROTECTED] wrote: Is there a conventional way to test for nested factors? I.e., if 'a' and 'b' are lists of same-length factors, does each level specified by 'a' correspond to exactly one level specified by 'b'? The function below seems to suffice, but I'd be

Re: [R] test for nested factors

2007-06-04 Thread Christophe Pallier
Here are two functions I wrote, 'is.nested' and 'are.crossed', that check whether a factor is nested inside antoher one, or if both are crossed: is.nested - function (factor1,factor2) { # only one positive number per line in the f1 * f2 crosstable