Re: [R] test whether all elements of a vector are identical

2010-12-17 Thread Daniel Murphy
> all(vector[1]==vector) should be quick. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and pro

Re: [R] test whether all elements of a vector are identical

2010-12-16 Thread David Winsemius
On Dec 16, 2010, at 10:19 AM, David Winsemius wrote: On Dec 16, 2010, at 9:56 AM, baptiste auguie wrote: Hi, The fastest way seems to be, all(x[1] == x) I'm sure that is more efficient than this methods: patt <- paste("^",x[1],"$", sep="") length( grep(patt, x) == length(x) ) Wrong po

Re: [R] test whether all elements of a vector are identical

2010-12-16 Thread David Winsemius
On Dec 16, 2010, at 9:56 AM, baptiste auguie wrote: Hi, The fastest way seems to be, all(x[1] == x) I'm sure that is more efficient than this methods: patt <- paste("^",x[1],"$", sep="") length( grep(patt, x) == length(x) ) ... but sometimes it helps to have strategies that might generali

Re: [R] test whether all elements of a vector are identical

2010-12-16 Thread baptiste auguie
Hi, The fastest way seems to be, all(x[1] == x) HTH, baptiste On 16 December 2010 15:17, Jannis wrote: > Dear list, > > > this might be an easy one, but I could figure out a solution (or how to > google the right term). > > Is there any way to test whether all elements of a vector are identi

Re: [R] test whether all elements of a vector are identical

2010-12-16 Thread David Winsemius
On Dec 16, 2010, at 9:17 AM, Jannis wrote: Dear list, this might be an easy one, but I could figure out a solution (or how to google the right term). Is there any way to test whether all elements of a vector are identical? ?identical For numeric vectors I would use sum(diff(vector

Re: [R] test whether all elements of a vector are identical

2010-12-16 Thread Jannis
Thanks Tal. Sometimes easy solutions are close by but hard to find when one is focused on the wrong direction :-)! Jannis Tal Galili schrieb: How about: length(unique(vector)) >1 ? Contact Details:--- Contact me: tal.gal..

Re: [R] test whether all elements of a vector are identical

2010-12-16 Thread Tal Galili
How about: length(unique(vector)) >1 ? Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -

[R] test whether all elements of a vector are identical

2010-12-16 Thread Jannis
Dear list, this might be an easy one, but I could figure out a solution (or how to google the right term). Is there any way to test whether all elements of a vector are identical? For numeric vectors I would use sum(diff(vector)==0)==0 but I have character vectors. Any Ideas? Cheers Janni