[R] test multiple objects for being equal length
Liaw, Andy
andy_liaw at merck.com
Thu Dec 9 15:39:52 CET 2004
Wrapping the suggestions into a function:
> sameLength <- function(...) {
+ n <- sapply(list(...), length)
+ all(n == n[1])
+ }
> sameLength(double(1), double(2))
[1] FALSE
> sameLength(double(1), double(1), list(x=1))
[1] TRUE
[Note that if you have lots of objects to compare, length(unique(...))==1
will not be as efficient.]
HTH,
Andy
> From: Manuel Gutierrez
>
> I could not find any help pages on How to test many
> objects for being of equal length
> Something like identical for more than two objects?
> x<-1:6
> y<-1:10
> z<-3:5
> ## For two objects I can do:
> identical(length(x),length(y))
> ## For more than two I currently can do:
> length(unique(c(length(x),length(y),length(z))))==1
>
> but there must be a better way.
> Thanks,
> M
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list