timeEvent: Time Near Events or Event Run Identification

Description Usage Arguments Value Examples

View source: R/Functions.R

Description

1
2
Counts the number of observations to/from an event.  This is called the time-distance to/from an event.
Alternately, gives the range of an event.

Usage

1
timeEvent(x, zone = "after", event = T, not = F, run = F, ...)

Arguments

x

xts object

zone

"after"(default). Before or after the event. "before" is the other option.

event

T(default). Detect the observation that holds the value of T(TRUE). This can be any value that can be testing on the right hand side of the equals (==) sign. A special option to be an event is NA.

not

F(default). Do not "!" not-the-event. T is useful against NA to detect !is.na(NA). The special case of NA internally is handled !is.na(NA).

run

F(default). Do not generate run range identifiers, instead return(T) the preferred time-distance from the event.

...

dots passed

Value

xts object

Examples

 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
## Not run: 

# timeEvent(Time Near Events or Event Run Identification) examples

xts(c(NA,F,F,T,NA,T,F,F,NA), zoo::as.Date(0:8))
            [,1]
1970-01-01    NA
1970-01-02 FALSE
1970-01-03 FALSE
1970-01-04  TRUE
1970-01-05    NA
1970-01-06  TRUE
1970-01-07 FALSE
1970-01-08 FALSE
1970-01-09    NA

timeEvent(xts(c(NA,F,F,T,NA,T,F,F,NA), zoo::as.Date(0:8)))

           V1te
1970-01-01   NA
1970-01-02   NA
1970-01-03   NA
1970-01-04    0
1970-01-05    1
1970-01-06    0
1970-01-07    1
1970-01-08    2
1970-01-09    3

timeEvent(xts(c(NA,F,F,T,NA,T,F,F,NA), zoo::as.Date(0:8)), run = T)

           V1te
1970-01-01   NA
1970-01-02   NA
1970-01-03   NA
1970-01-04    1
1970-01-05    1
1970-01-06    2
1970-01-07    2
1970-01-08    2
1970-01-09    2

timeEvent(xts(c(NA,F,F,T,NA,T,F,F,NA), zoo::as.Date(0:8)), zone = "before")

           V1te
1970-01-01    3
1970-01-02    2
1970-01-03    1
1970-01-04    0
1970-01-05    1
1970-01-06    0
1970-01-07   NA
1970-01-08   NA
1970-01-09   NA

timeEvent(xts(c(NA,F,F,T,NA,T,F,F,NA), zoo::as.Date(0:8)), zone = "before", run = T)

           V1te
1970-01-01    2
1970-01-02    2
1970-01-03    2
1970-01-04    2
1970-01-05    1
1970-01-06    1
1970-01-07   NA
1970-01-08   NA
1970-01-09   NA

## End(Not run)

AndreMikulec/econModel documentation built on June 30, 2021, 9:48 a.m.