[R] test multiple objects for being equal length

Eric Lecoutre lecoutre at stat.ucl.ac.be
Thu Dec 9 09:17:29 CET 2004


Hi Manuel,

First, encapsulate yoyr objects within a list. That will help you 
manipulate all them at once and ensures that the final function will work 
with whatever number of vectors.

» ll <- list(x,y,z)
» sapply(ll,length)
[1]  6 10  3

Then you can use your length(unique(...))==1
Another way is to use all:

» all(sapply(ll,length)==length(ll[[1]]))
[1] FALSE

HTH,

Eric



At 09:09 9/12/2004, Manuel Gutierrez wrote:
>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

Eric Lecoutre
UCL /  Institut de Statistique
Voie du Roman Pays, 20
1348 Louvain-la-Neuve
Belgium

tel: (+32)(0)10473050
lecoutre at stat.ucl.ac.be
http://www.stat.ucl.ac.be/ISpersonnel/lecoutre

If the statistics are boring, then you've got the wrong numbers. -Edward 
Tufte




More information about the R-help mailing list