This 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, ...)

Arguments

x

a vector, matrix, data.frame, xts, timeSeries or zoo object to be checked and coerced

method

type of coerced data object to return, one of c("xts", "zoo", "data.frame", "matrix", "vector"), default "xts"

na.rm

TRUE/FALSE Remove NA's from the data? used only with 'vector'

quiet

TRUE/FALSE if false, it will throw warnings when errors are noticed, default TRUE

any other passthru parameters

Examples

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 #> 2009-03-31 0.0235 -0.0180 0.0022 #> 2009-04-30 0.0500 -0.0140 0.0387 #> 2009-05-31 0.0578 0.0213 0.0504 #> 2009-06-30 0.0241 -0.0147 0.0198 #> 2009-07-31 0.0611 -0.0012 0.0311 #> 2009-08-31 0.0315 0.0054 0.0244 #> Emerging Markets Equity Market Neutral Event Driven #> 2009-03-31 0.0350 0.0021 0.0117 #> 2009-04-30 0.0663 -0.0012 0.0337 #> 2009-05-31 0.0884 0.0146 0.0442 #> 2009-06-30 0.0013 0.0036 0.0123 #> 2009-07-31 0.0451 0.0042 0.0291 #> 2009-08-31 0.0166 0.0070 0.0207 #> Fixed Income Arbitrage Global Macro Long/Short Equity #> 2009-03-31 0.0057 0.0048 0.0188 #> 2009-04-30 0.0221 0.0127 0.0375 #> 2009-05-31 0.0365 0.0348 0.0516 #> 2009-06-30 0.0126 -0.0076 0.0009 #> 2009-07-31 0.0322 0.0166 0.0277 #> 2009-08-31 0.0202 0.0050 0.0157 #> Merger Arbitrage Relative Value Short Selling Funds of Funds #> 2009-03-31 0.0125 0.0100 -0.0462 0.0008 #> 2009-04-30 0.0081 0.0342 -0.0820 0.0092 #> 2009-05-31 0.0107 0.0392 0.0008 0.0312 #> 2009-06-30 0.0104 0.0101 -0.0094 0.0024 #> 2009-07-31 0.0068 0.0260 -0.0596 0.0153 #> 2009-08-31 0.0102 0.0162 -0.0165 0.0113
# 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"
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