R/checkData.R
checkData.RdThis function was created to make the different kinds of data classes at
least seem more fungible. It allows the user to pass in a data
object without being concerned that the function requires a matrix,
data.frame, vector, xts, or timeSeries object. By using checkData,
the function "knows" what data format it has to work with.
checkData(
x,
method = c("xts", "zoo", "data.frame", "matrix", "vector"),
na.rm = TRUE,
quiet = TRUE,
...
)a vector, matrix, data.frame, xts, timeSeries or zoo object to be checked and coerced
type of coerced data object to return, one of c("xts", "zoo", "data.frame", "matrix", "vector"), default "xts"
TRUE/FALSE Remove NA's from the data? used only with 'vector'
TRUE/FALSE if false, it will throw warnings when errors are noticed, default TRUE
any other passthru parameters
data(edhec)
x = checkData(edhec)
class(x)
#> [1] "xts" "zoo"
head(x)
#> Convertible Arbitrage CTA Global Distressed Securities
#> 1997-01-31 0.0119 0.0393 0.0178
#> 1997-02-28 0.0123 0.0298 0.0122
#> 1997-03-31 0.0078 -0.0021 -0.0012
#> 1997-04-30 0.0086 -0.0170 0.0030
#> 1997-05-31 0.0156 -0.0015 0.0233
#> 1997-06-30 0.0212 0.0085 0.0217
#> Emerging Markets Equity Market Neutral Event Driven
#> 1997-01-31 0.0791 0.0189 0.0213
#> 1997-02-28 0.0525 0.0101 0.0084
#> 1997-03-31 -0.0120 0.0016 -0.0023
#> 1997-04-30 0.0119 0.0119 -0.0005
#> 1997-05-31 0.0315 0.0189 0.0346
#> 1997-06-30 0.0581 0.0165 0.0258
#> Fixed Income Arbitrage Global Macro Long/Short Equity
#> 1997-01-31 0.0191 0.0573 0.0281
#> 1997-02-28 0.0122 0.0175 -0.0006
#> 1997-03-31 0.0109 -0.0119 -0.0084
#> 1997-04-30 0.0130 0.0172 0.0084
#> 1997-05-31 0.0118 0.0108 0.0394
#> 1997-06-30 0.0108 0.0218 0.0223
#> Merger Arbitrage Relative Value Short Selling Funds of Funds
#> 1997-01-31 0.0150 0.0180 -0.0166 0.0317
#> 1997-02-28 0.0034 0.0118 0.0426 0.0106
#> 1997-03-31 0.0060 0.0010 0.0778 -0.0077
#> 1997-04-30 -0.0001 0.0122 -0.0129 0.0009
#> 1997-05-31 0.0197 0.0173 -0.0737 0.0275
#> 1997-06-30 0.0231 0.0198 -0.0065 0.0225
tail(x)
#> Convertible Arbitrage CTA Global Distressed Securities
#> 2020-12-31 0.0217 0.0452 0.0307
#> 2021-01-31 0.0247 -0.0032 0.0239
#> 2021-02-28 0.0189 0.0315 0.0316
#> 2021-03-31 -0.0048 0.0045 0.0163
#> 2021-04-30 -0.0001 0.0250 0.0216
#> 2021-05-31 0.0056 0.0164 0.0168
#> Emerging Markets Equity Market Neutral Event Driven
#> 2020-12-31 0.0454 0.0150 0.0451
#> 2021-01-31 0.0205 0.0003 0.0168
#> 2021-02-28 0.0162 0.0139 0.0372
#> 2021-03-31 -0.0081 0.0102 0.0160
#> 2021-04-30 0.0257 0.0147 0.0276
#> 2021-05-31 0.0209 0.0035 0.0125
#> Fixed Income Arbitrage Global Macro Long/Short Equity
#> 2020-12-31 0.0138 0.0375 0.0444
#> 2021-01-31 0.0143 0.0012 -0.0009
#> 2021-02-28 0.0039 0.0149 0.0442
#> 2021-03-31 0.0056 0.0093 0.0075
#> 2021-04-30 0.0092 0.0233 0.0249
#> 2021-05-31 0.0030 0.0188 0.0085
#> Merger Arbitrage Relative Value Short Selling Funds of Funds
#> 2020-12-31 0.0471 0.0184 0.000 0.0313
#> 2021-01-31 0.0352 0.0105 0.000 -0.0095
#> 2021-02-28 0.0188 0.0159 0.009 0.0274
#> 2021-03-31 -0.0135 0.0054 0.002 0.0004
#> 2021-04-30 0.0234 0.0109 0.000 0.0189
#> 2021-05-31 0.0058 0.0067 0.000 0.0022
# Note that passing in a single column loses the row and column names
x = checkData(edhec[,1])
class(x)
#> [1] "xts" "zoo"
head(x)
#> Convertible Arbitrage
#> 1997-01-31 0.0119
#> 1997-02-28 0.0123
#> 1997-03-31 0.0078
#> 1997-04-30 0.0086
#> 1997-05-31 0.0156
#> 1997-06-30 0.0212
# Include the "drop" attribute to keep row and column names
x = checkData(edhec[,1,drop=FALSE])
class(x)
#> [1] "xts" "zoo"
head(x)
#> Convertible Arbitrage
#> 1997-01-31 0.0119
#> 1997-02-28 0.0123
#> 1997-03-31 0.0078
#> 1997-04-30 0.0086
#> 1997-05-31 0.0156
#> 1997-06-30 0.0212
x = checkData(edhec, method = "matrix")
class(x)
#> [1] "matrix" "array"
head(x)
#> Convertible Arbitrage CTA Global Distressed Securities
#> 1997-01-31 0.0119 0.0393 0.0178
#> 1997-02-28 0.0123 0.0298 0.0122
#> 1997-03-31 0.0078 -0.0021 -0.0012
#> 1997-04-30 0.0086 -0.0170 0.0030
#> 1997-05-31 0.0156 -0.0015 0.0233
#> 1997-06-30 0.0212 0.0085 0.0217
#> Emerging Markets Equity Market Neutral Event Driven
#> 1997-01-31 0.0791 0.0189 0.0213
#> 1997-02-28 0.0525 0.0101 0.0084
#> 1997-03-31 -0.0120 0.0016 -0.0023
#> 1997-04-30 0.0119 0.0119 -0.0005
#> 1997-05-31 0.0315 0.0189 0.0346
#> 1997-06-30 0.0581 0.0165 0.0258
#> Fixed Income Arbitrage Global Macro Long/Short Equity
#> 1997-01-31 0.0191 0.0573 0.0281
#> 1997-02-28 0.0122 0.0175 -0.0006
#> 1997-03-31 0.0109 -0.0119 -0.0084
#> 1997-04-30 0.0130 0.0172 0.0084
#> 1997-05-31 0.0118 0.0108 0.0394
#> 1997-06-30 0.0108 0.0218 0.0223
#> Merger Arbitrage Relative Value Short Selling Funds of Funds
#> 1997-01-31 0.0150 0.0180 -0.0166 0.0317
#> 1997-02-28 0.0034 0.0118 0.0426 0.0106
#> 1997-03-31 0.0060 0.0010 0.0778 -0.0077
#> 1997-04-30 -0.0001 0.0122 -0.0129 0.0009
#> 1997-05-31 0.0197 0.0173 -0.0737 0.0275
#> 1997-06-30 0.0231 0.0198 -0.0065 0.0225
x = checkData(edhec[,1], method = "vector")
class(x)
#> [1] "numeric"
head(x)
#> [1] 0.0119 0.0123 0.0078 0.0086 0.0156 0.0212