On 2020-08-14 13:58 -0700, Philip wrote:
| I’m trying to compare National Weather 
| Service Rapid Update Forecast (RAP) 
| data to GPS breadcrumbs collected by a 
| really clever Apple Phone Ap that lays 
| down longitude, latitude, altitude, 
| compass direction, and speed every six 
| seconds.   Below is a small subset of 
| the GPS data from another flight.  
| 
| I want to delete the rows where the 
| balloon does not move (Speed column) 
| for a full minute assuming that it is 
| sitting on the ground – beginning of 
| the flight, changing passengers, or 
| waiting for the chase crew at the end 
| of the flight.  for example, I want to 
| eliminate the data for minute 30 but 
| keep the data for minute 31 because 
| the balloon starts to move again at 
| second 17.  Any suggestions?  I’ve 
| tried putzing around with multiple 
| lags without success.
| 
|       Minute Second Speed 
|       [...]
| 
| It would be even better if I could 
| delete the rows where there were ten 
| consecutive zero speed entries such as 
| from minute 30 second 17 to minute 31 
| second 11.

Dear Philip,

first I though about solving this using 
some combination of unique, duplicated, 
table ... then I saw Jim's reply, and 
rewrote it a little:

        rap <-
        structure(list(Minute = c(29L, 29L, 29L,
        30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 
        30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 
        31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 
        31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 
        31L, 31L, 31L, 31L, 31L, 31L, 32L), 
        Second = c(47L, 53L, 59L, 5L, 11L, 17L, 
        23L, 29L, 35L, 41L, 47L, 53L, 59L, 5L, 
        11L, 17L, 23L, 29L, 35L, 41L, 43L, 43L, 
        43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 
        43L, 43L, 47L, 53L, 54L, 54L, 54L, 54L, 
        54L, 54L, 59L, 5L), 
        Speed = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
        0, 0, 0, 0, 0, 0.402649, 0.671081, 
        1.588225, 2.438261, 2.706693, 0, 0, 0, 
        0, 0, 0, 0, 0, 0, 0, 0, 0, 2.930386, 
        3.310666, 0, 0, 0, 0, 0, 0, 3.198819, 
        3.422512)), class = "data.frame", 
        row.names = c(NA, -42L))
        
        minis <- unique(rap$Minute)
        FUN <- function(mini, rap) {
          all(rap$Speed[rap$Minute==mini]==0) }
        keep <- rap$Minute %in%
          minis[!simplify2array(
            parallel::mclapply(minis, FUN, rap))]
        rap[keep,]

As to Bert's reply, I am a loss as how 
to use the lengths list in 
rle(rap$Speed) for this ...

Best,
Rasmus

Attachment: signature.asc
Description: PGP signature

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to