Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

checkData

check input data type and format and coerce to the desired output type


Description

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.

Usage

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

Author(s)

Peter Carl

Examples

data(edhec)
x = checkData(edhec)
class(x)
head(x)
tail(x)
# Note that passing in a single column loses the row and column names
x = checkData(edhec[,1])
class(x)
head(x)
# Include the "drop" attribute to keep row and column names
x = checkData(edhec[,1,drop=FALSE])
class(x)
head(x)
x = checkData(edhec, method = "matrix")
class(x)
head(x)
x = checkData(edhec[,1], method = "vector")
class(x)
head(x)

PerformanceAnalytics

Econometric Tools for Performance and Risk Analysis

v2.0.4
GPL-2 | GPL-3
Authors
Brian G. Peterson [cre, aut, cph], Peter Carl [aut, cph], Kris Boudt [ctb, cph], Ross Bennett [ctb], Joshua Ulrich [ctb], Eric Zivot [ctb], Dries Cornilly [ctb], Eric Hung [ctb], Matthieu Lestel [ctb], Kyle Balkissoon [ctb], Diethelm Wuertz [ctb], Anthony Alexander Christidis [ctb], R. Douglas Martin [ctb], Zeheng 'Zenith' Zhou [ctb], Justin M. Shea [ctb]
Initial release
2020-02-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.