An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130612/68e1f233/attachment.pl>
identify data points by certain criteria
4 messages · David Winsemius, arun, Ye Lin
On Jun 12, 2013, at 5:55 PM, Ye Lin wrote:
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")
While you are waiting for an answer you might want to read the Posting Guide: http://www.R-project.org/posting-guide.html Points to pay special attention to: Plain-text. Posting code. Posting examples in form that can be pasted into console session (dump or dput functions). Providing context for problem (such as describing the conventions for your time-scale) and your background (since this looks like a homework exercise.)
Thanks for your help! [[alternative HTML version deleted]]
______________________________________________
David Winsemius Alameda, CA, USA
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130613/63e0e1ff/attachment.pl>