Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.77 KB | None | 0 0
  1. require(zoo)
  2. require(chron)
  3.  
  4. fmt = "%m/%d/%Y %H:%M"
  5. tail1 = function(x) tail(x, 1)
  6.  
  7. old = read.zoo("old.txt", header = F,
  8.    FUN = as.chron, format = fmt,
  9.    colClasses = c(NA, "numeric", "NULL"),
  10.    sep = "\t", aggregate = tail1)
  11.  
  12. new = read.zoo("new.txt", header = T,
  13.    FUN = as.chron, format = fmt,
  14.    sep = ",",
  15.    colClasses = c("NULL", NA, "numeric",
  16.       "NULL", "NULL",
  17.       "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL",
  18.       "NULL", "NULL", "NULL", "NULL", "NULL", "NULL"),  
  19.    aggregate = tail1)
  20.  
  21. min = seq(start(new), end(new), by = times("00:01:00"))
  22. intData = na.approx(new, xout = min)
  23.  
  24. min = times("00:15:00")
  25. offset = min*1/2
  26.  
  27. avgData = suppressWarnings(aggregate(intData,
  28.    trunc(time(intData) + offset, min), mean))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement