Skip to content
Prev 325361 / 398503 Next

identify data points by certain criteria

Hi,
Check if this works for you:
source("Ye_data.txt")
?dim(dat1)
library(xts)
?xt1<- xts(dat1[,-1],strptime(dat1[,1],"%m/%d/%Y %H:%M"))
xtSub<-xt1["T00:00:00/T08:00:00"]
lst1<-split(xtSub,as.Date(index(xtSub)))
res<- do.call(rbind,lapply(lst1,function(x){indx<- which(rowSums(x)==0);x[indx[which.max(c(diff(indx),0))],]}))
tail(res)

? # ????????????????? Var1 Var2
#2012-12-26 03:49:00??? 0??? 0
#2012-12-27 02:24:00??? 0??? 0
#2012-12-28 06:13:00??? 0??? 0
#2012-12-29 02:02:00??? 0??? 0
#2012-12-30 06:37:00??? 0??? 0
#2012-12-31 07:07:00??? 0??? 0
A.K.


----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: Ye Lin <yelin at lbl.gov>
Cc: 
Sent: Thursday, June 13, 2013 10:04 PM
Subject: Re: [R] identify data points by certain criteria




"""
e.g. 12/31, the time period where sum(Var1+Var2)=0 are:

?from 00:00:00 to 00:55:00 (55 min)

from 01:07:00 to 07:07:00 ? (6h=360min)
from 07:43:00 to 08:00:00 ? (17min)

then when apply "sapply(lst1,function(x) {indx <- 
which(rowSums(x)==0);indx1 <- 
which.max(c(1,diff(index(x)[indx])))})", for 12/31 it should return 360 
and 01:07:00

"""

I was trying to understand what you meant by 55 min and 360 min in this case: here, the rows from 1:07:00 to 07:07:00 are zero's for Var1 and Var2.? So, the difference should be 1,1,1,........................1 instead of 55, and 360.? If the 01:07:00 row had both the rows==0 and then all the rows until 07:07:00 have either one of the variables>0, then the difference should 360.? Do you think so?
Message-ID: <1371176512.21206.YahooMailNeo@web142606.mail.bf1.yahoo.com>
In-Reply-To: <1371175479.61348.YahooMailNeo@web142602.mail.bf1.yahoo.com>