Check if a variable is xts or data.frame

MichiZH picture MichiZH · Feb 19, 2014 · Viewed 24.9k times · Source

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?

Answer

tonytonov picture tonytonov · Feb 19, 2014

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