Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a variable is xts or data.frame

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?

like image 775
MichiZH Avatar asked Feb 19 '14 13:02

MichiZH


People also ask

How do I find the data type of a variable in R?

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.

How do you know if something is a pandas series?

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.


1 Answers

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
like image 122
tonytonov Avatar answered Sep 20 '22 08:09

tonytonov