File: MATCH.R

package info (click to toggle)
r-zoo 1.8-14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,760 kB
  • sloc: ansic: 373; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,327 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
MATCH <- function(x, table, nomatch = NA, ...)
  UseMethod("MATCH")
  
MATCH.default <- function(x, table, nomatch = NA, ...) {
  if(is.atomic(x) && !is.object(x)) {
    if(inherits(table, "Date")) {
      x <- unclass(as.Date(x, origin = "1970-01-01"))
      table <- unclass(table)
    } else if(inherits(table, "POSIXt")) {
      x <- unclass(as.POSIXct(x, origin = "1970-01-01"))
      table <- unclass(as.POSIXct(table))
    }
  }
  match(x, table, nomatch = nomatch, ...)
}

MATCH.timeDate <- function(x, table, nomatch = NA, ...) {
  match(as.POSIXct(x), as.POSIXct(table), nomatch = nomatch, ...)
}

MATCH.times <- function(x, table, nomatch = NA, units = "sec", eps = 1e-10, ...) {
 match(trunc(x, units, eps), trunc(table, units, eps), nomatch = nomatch, ...)
}

MATCH.Date <- function(x, table, nomatch = NA, ...) {
  if(!inherits(table, "Date")) table <- as.Date(table)
  match(unclass(x), unclass(table), nomatch = nomatch, ...)
}

MATCH.POSIXct <- function(x, table, nomatch = NA, ...) {
  if(!inherits(table, "POSIXct")) table <- as.POSIXct(table)
  match(unclass(x), unclass(table), nomatch = nomatch, ...)
}

MATCH.POSIXlt <- function(x, table, nomatch = NA, ...) {
  x <- as.POSIXct(x)
  if(!inherits(table, "POSIXct")) table <- as.POSIXct(table)
  match(unclass(x), unclass(table), nomatch = nomatch, ...)
}