Well the question says it all..I want to check in one of my functions if a function parameter given is of xts or data frame type. How can I do this?
There are several ways to check data type in R. We can make use of the “typeof()” function, “class()” function and even the “str()” function to check the data type of an entire dataframe.
To check the data type of a Series we have a dedicated attribute in the pandas series properties. The “dtype” is a pandas attribute that is used to verify data type in a pandas Series object. This attribute will return a dtype object which represents the data type of the given series.
It is a general practice to add is.smth
and as.smth
functions for these types of checks and conversions:
df <- data.frame()
xt <- xts()
is.data.frame(df)
[1] TRUE
is.data.frame(xt)
[1] FALSE
is.xts(df)
[1] FALSE
is.xts(xt)
[1] TRUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With