[R] identify data points by certain criteria

arun smartpink111 at yahoo.com
Thu Jun 13 03:29:26 CEST 2013


Hi,
Not clear about the 'Time' column.
dat1<- read.table(text="
Time    Var1      Var2
00:00    1              0
00:01    0              0
00:02    1              0
00:03    1              0
00:04    0              0
00:05    1              0
00:06    1              0
00:07    1              0
00:08    1              0
00:09    0              0
00:10    1              0
00:11    1              0
00:12    1              0
00:13    0              0
",sep="",header=TRUE,stringsAsFactors=FALSE)


indx<-which(rowSums(dat1[,-1])==0)
dat1[indx[which.max(c(1,diff(as.numeric(gsub(".*:","",dat1[,1][indx])))))],]
#    Time Var1 Var2
#10 00:09    0    0
dat1[indx[which.max(c(1,diff(as.numeric(gsub(".*:","",dat1[,1][indx])))))],"Time"]
#[1] "00:09"


A.K.



----- Original Message -----
From: Ye Lin <yelin at lbl.gov>
To: R help <r-help at r-project.org>
Cc: 
Sent: Wednesday, June 12, 2013 8:55 PM
Subject: [R] identify data points by certain criteria

Hey I want to identify data points by criteria, here is an example of my
1min data

Time     Var1      Var2
00:00    1              0
00:01    0              0
00:02    1              0
00:03    1              0
00:04    0              0
00:05    1              0
00:06    1              0
00:07    1              0
00:08    1              0
00:09    0              0
00:10    1              0
00:11    1              0
00:12    1              0
00:13    0              0

I want to identify the data points where Var1=0 and Var2=0, ( in this
example shud be the points highlighted above), then calculate the time
duration between these data points, (in this example, shud be 3min, 5 min
and 4min), then identify the starting point of the max time duration ( in
this example shud be the starting point of 5-min-duration, return the data
points at 00:09), finally return the value in "Time" column ( in this
example shud be "00:09")

Thanks for your help!

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list