[R] diff question

Rolf Turner r.turner at auckland.ac.nz
Sun Jan 11 09:57:36 CET 2015



See FAQ 7.31.

cheers,

Rolf Turner

On 11/01/15 21:29, Troels Ring wrote:
> 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.


-- 
Rolf Turner
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
Home phone: +64-9-480-4619



More information about the R-help mailing list