Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. ## Create a data.frame of 10-minute intervals stored as POSIXct
  2. ## You can convert most times to POSIXct using as.POSIXct if they are not already that format
  3. lizard <- data.frame(time=seq(from=as.POSIXct('2015-01-01 00:00:00'), to=as.POSIXct('2015-01-02 00:00:00'), by=10*60))
  4.  
  5. ## Randomly eliminate rows with probability of 15% that a given row is eliminated to create gaps
  6. lizard$keep = runif(nrow(lizard))
  7. lizard <- lizard[lizard$keep <= .85, c('time'), drop=FALSE] ## drop arg used to kepe it a dataframe
  8.  
  9. ## Random lat / lon data:
  10. lizard$Lat = runif(nrow(lizard)) ## runif is random uniform
  11. lizard$Lon = runif(nrow(lizard))
  12.  
  13. ## We initialize to NA; the distance variable for row i will represent the distance between row i-1 and i;
  14. ## row 1 will not have a meaningful value
  15. lizard$distance <- NA
  16. lizard$distance[2:nrow(lizard)] <- distanceTrack(lizard$Lat, lizard$Lon)
  17.  
  18. lizard$isContiguous <- TRUE ## initialize a variable to determine if the data is at 10-min interval
  19. lizard$isContiguous[2:nrow(lizard)] <- (as.numeric(lizard$time[2:nrow(lizard)] - lizard$time[1:nrow(lizard) - 1]) == 10)
  20. lizard <- lizard[lizard$isContiguous, ] ## filter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement