1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| tab <- structure(list(Date = structure(1:7, .Label = c("06-06-2018 15:00:58",
"06-06-2018 15:00:59", "06-06-2018 15:01:05", "06-06-2018 15:01:18",
"06-06-2018 15:01:36", "06-06-2018 15:01:48", "06-06-2018 15:01:50"
), class = "factor"), Capteur.1 = structure(c(2L, 2L, 2L, 2L,
2L, 1L, 1L), .Label = c("OFF", "ON"), class = "factor"), Capteur.2 = structure(c(1L,
1L, 2L, 2L, 2L, 2L, 1L), .Label = c("OFF", "ON"), class = "factor")), .Names = c("Date",
"Capteur.1", "Capteur.2"), class = "data.frame", row.names = c(NA,
-7L))
tab$Date <- as.POSIXct(tab$Date, format = "%d-%m-%Y %H:%M:%S")
d1 <- diff(tab$Date[sapply(tab[-1], function(x) which(x=="ON")[1])])
d1
Time difference of 7 secs
sapply(tab[2:3], function(x) diff(range(tab$Date[x!="OFF"])))
Capteur.1 Capteur.2
38 43 |
Partager