Skip to content
Prev 333527 / 398513 Next

How do I identify non-sequential data?

Hi Don,

Yes, I am error checking a dataset produced by a query.  Most likely a problem with the query but wanted to assess the problem first.

BTW Arun provided another solution which is similar to yours but uses the function ave instead:
 testSeq[!!(with(testSeq,ave(YoS,ID,FUN=function(x) any(c(0,diff(x))>1)))),]

I appreciate your response on this.
Dan


-----Original Message-----
From: MacQueen, Don 
Sent: Thursday, November 21, 2013 3:58 PM
To: Lopez, Dan; R help (r-help at r-project.org)
Subject: Re: [R] How do I identify non-sequential data?

Dan,
Does this do it?

## where dt is the data

tmp <- split(dt, dt$ID)

foo <- lapply(tmp, function(x) any(diff(x$YoS) > 1))

foo <- data.frame( ID=names(foo), gap=unlist(foo))

Note that I ignored dept.
Little hard to see how YoS can increase by more than one when the year increases by only one ... unless this is a search for erroneous data.

-Don



--
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 11/21/13 3:32 PM, "Lopez, Dan" <lopez235 at llnl.gov> wrote:

            
Message-ID: <56180B40A4F72A4083C75B30DA86297333DB3FAF@PRDEXMBX-05.the-lab.llnl.gov>
In-Reply-To: <5E1B812FAC2C4A49B3D99593B5A521910D596949@PRDEXMBX-08.the-lab.llnl.gov>