[R] delete repeated values in array
arun
smartpink111 at yahoo.com
Sat Aug 31 03:33:14 CEST 2013
Hi,
May be this helps:
rle(try)$values
#[1] 1 2 3 1 2 4
#or
aggregate(try,list(cumsum(c(1,abs(diff(try))))),unique)[,2]
#[1] 1 2 3 1 2 4
#or
res<-tapply(try,cumsum(c(1,abs(diff(try)))),head,1)
attr(res,"dimnames")<-NULL
res
#[1] 1 2 3 1 2 4
A.K.
I am trying to delete repeated values in an array.
try <- c(1,1,1,1,1,2,2,2,3,3,3,1,1,1,2,2,4,4,4)
what I want back is:
1 2 3 1 2 4
so unique() doesn't work for my purposes as it would give me:
1 2 3 4
More information about the R-help
mailing list