Re: [R] how to checking whether elements of a vector changed or not.

2009-06-02 Thread David Winsemius
The point was that I thought you had reversed the intent of the t/f values. Looking back at the OP's request I see that it was probably me that was doing the reversal. Pardon me. -- David Winsemius On Jun 2, 2009, at 9:40 PM, Gabor Grothendieck wrote: Its not clear to me what your point i

Re: [R] how to checking whether elements of a vector changed or not.

2009-06-02 Thread Gabor Grothendieck
Its not clear to me what your point is. Perhaps you could elaborate. On Tue, Jun 2, 2009 at 4:32 PM, David Winsemius wrote: > Gabor; > > Did you perhaps get an undesired doubling of "!"? > >> x1 <-c("A", "A", "B", "B", "B", "A") >> x1[2:length(x1)] == x1[1:(length(x1)-1)] > [1]  TRUE FALSE  TRUE

Re: [R] how to checking whether elements of a vector changed or not.

2009-06-02 Thread David Winsemius
Gabor; Did you perhaps get an undesired doubling of "!"? > x1 <-c("A", "A", "B", "B", "B", "A") > x1[2:length(x1)] == x1[1:(length(x1)-1)] [1] TRUE FALSE TRUE TRUE FALSE > !!diff(c(factor(x1))) [1] FALSE TRUE FALSE FALSE TRUE (Your trick of computing differences of the underlying factor

Re: [R] how to checking whether elements of a vector changed or not.

2009-06-02 Thread Linlin Yan
> c(x[1], x[-length(x)]) != x [1] FALSE FALSE FALSE TRUE TRUE FALSE TRUE On Mon, Jun 1, 2009 at 11:57 PM, liujb wrote: > > Hello, > > I have a vector: > x <- c("A", "A", "A", "B", "A", "A", "C") > > I'd like to compare each of elements of vector x from its previous element > (except for the 1s

Re: [R] how to checking whether elements of a vector changed or not.

2009-06-01 Thread Gabor Grothendieck
Try this: c(FALSE, !!diff(c(factor(x On Mon, Jun 1, 2009 at 11:57 AM, liujb wrote: > > Hello, > > I have a vector: > x <- c("A", "A", "A", "B", "A", "A", "C") > > I'd like to compare each of elements of vector x from its previous element > (except for the 1st element which does not have pre

[R] how to checking whether elements of a vector changed or not.

2009-06-01 Thread liujb
Hello, I have a vector: x <- c("A", "A", "A", "B", "A", "A", "C") I'd like to compare each of elements of vector x from its previous element (except for the 1st element which does not have previous element). So I'd like to get a vector y (of same length) that looks something like (0, 0, 0, 1, 1,