[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]]))



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?
>## For two objects I can do:
>## For more than two I currently can do:
>but there must be a better way.
>R-help at stat.math.ethz.ch mailing list
>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

tel: (+32)(0)10473050
lecoutre at stat.ucl.ac.be

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

More information about the R-help mailing list