[R] diff question

Troels Ring tring at gvdnet.dk
Sun Jan 11 09:29:26 CET 2015


R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

Dear friends - I have a small problem with diff (I guess)
I made a sequence with fixed interval between consecutive elements - and 
hence thought the  diff would be as specified
but had a vector with apparently identical 12 elements returned from diff
tt <- seq(0,20,by=0.02)
unique(diff(tt)) #[1] 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 0.02 
0.02 0.02
Trying to see if these elements in diff were duplicated
duplicated(diff(tt))
#[1] FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE  TRUE and from
sum(duplicated(diff(tt)))
[1] 988
saw that 12 of the elements in duplicated(diff(tt)) were FALSE. Would it 
be expected that the first was FALSE and the rest TRUE?
|duplicated()|determines which elements of a vector or data frame are 
duplicates of elements with smaller subscripts, and returns a logical 
vector indicating which elements (rows) are duplicates.

All best wishes
Troels
Aalborg, Denmark

	[[alternative HTML version deleted]]



More information about the R-help mailing list