pairWise: Pairwise Interleave of Two "Two Dimensional" Index-able...

Description Usage Arguments Value Examples

View source: R/explode.R

Description

1
2
3
If one or the other has one index element while the other
has N index elements, then the one will be recycled to N index elements.
Consider, instead, using multiWise.

Usage

1
pairWise(x, y)

Arguments

x

two dimension index-able object

y

two dimension index-able object

Value

list of length two of two interleaved two dimensional index-able objects

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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
## Not run: 

list(iris[1:2,1:2], airquality[1:2,1:2])
[[1]]
  Sepal.Length Sepal.Width
1          5.1         3.5
2          4.9         3.0

[[2]]
  Ozone Solar.R
1    41     190
2    36     118

str( pairWise( iris[1:2,1:2], airquality[1:2,1:2] ) )
List of 2
 $ :List of 2
  ..$ Sepal.Length: num [1:2] 5.1 4.9
  ..$ Ozone       : int [1:2] 41 36
 $ :List of 2
  ..$ Sepal.Width: num [1:2] 3.5 3
  ..$ Solar.R    : int [1:2] 190 118

# 1 by N recycling
#
 str( pairWise( iris[1:2,1:2], airquality[1:2,1, drop = F] ) )
 List of 2
  $ :List of 2
   ..$ Sepal.Length: num [1:2] 5.1 4.9
   ..$ Ozone       : int [1:2] 41 36
  $ :List of 2
   ..$ Sepal.Width: num [1:2] 3.5 3
   ..$ Ozone      : int [1:2] 41 36

library(xts)
data("sample_matrix", package = "xts")
str( pairWise(as.xts(sample_matrix)[,1:2], as.xts(sample_matrix)[,3:4] ) )
List of 2
 $ :List of 2
  ..$ Open:An 'xts' object on 2007-01-02/2007-06-30 containing:
  Data: num [1:180, 1] 50 50.2 50.4 50.4 50.2 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "Open"
  Indexed by objects of class: [POSIXct,POSIXt] TZ:
  xts Attributes:
 NULL
  ..$ Low :An 'xts' object on 2007-01-02/2007-06-30 containing:
  Data: num [1:180, 1] 50 50.2 50.3 50.2 50.1 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "Low"
  Indexed by objects of class: [POSIXct,POSIXt] TZ:
  xts Attributes:
 NULL
 $ :List of 2
  ..$ High :An 'xts' object on 2007-01-02/2007-06-30 containing:
  Data: num [1:180, 1] 50.1 50.4 50.4 50.4 50.2 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "High"
  Indexed by objects of class: [POSIXct,POSIXt] TZ:
  xts Attributes:
 NULL
  ..$ Close:An 'xts' object on 2007-01-02/2007-06-30 containing:
  Data: num [1:180, 1] 50.1 50.4 50.3 50.3 50.2 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "Close"
  Indexed by objects of class: [POSIXct,POSIXt] TZ:
  xts Attributes:
 NULL

library(quantmod)
ibm <- quantmod::getSymbols("IBM", from = "1970-01-01", to = "1970-01-13", auto.assign = FALSE)
pairWise(tail(ibm[,c("IBM.Open","IBM.Close")]), xts(, zoo::as.Date(0)[0]))

[[1]]
[[1]]$IBM.Open
IBM.Open
1970-01-05   18.300
1970-01-06   18.413
1970-01-07   18.425
1970-01-08   18.438
1970-01-09   18.475
1970-01-12   18.450

[[1]][[2]]
Data:
  numeric(0)

Index:
  integer(0)

[[2]]
[[2]]$IBM.Close
IBM.Close
1970-01-05    18.413
1970-01-06    18.425
1970-01-07    18.438
1970-01-08    18.475
1970-01-09    18.450
1970-01-12    18.388

[[2]][[2]]
Data:
  numeric(0)

Index:
  integer(0)

pairWise(tail(ibm[,c("IBM.Open")]), xts())
[[1]]
[[1]]$IBM.Open
IBM.Open
1970-01-05   18.300
1970-01-06   18.413
1970-01-07   18.425
1970-01-08   18.438
1970-01-09   18.475
1970-01-12   18.450

[[1]][[2]]
Data:
  numeric(0)

Index:
  integer(0)



## End(Not run)

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