Pergunta

I thought it was for turning a xts object to its original class, but after I pass an xts object into it, it did not give me the original object back. What does it for?

My attempt

data(sample_matrix)
class(sample_matrix)
#"matrix"
class(reclass(as.xts(sample_matrix)))
#"xts" "zoo"
Foi útil?

Solução

From the docs

try.xts and reclass are functions that enable external developers access to the reclassing tools within xts to help speed development of time-aware functions, as well as provide a more robust and seemless end-user experience, regardless of the end-user's choice of data-classes.

if you use try.xts to convert a xtsible object to xts object , reclass or Reclass both should be able to convert it back to it's original class with all attributes intact.

class(Reclass(try.xts(sample_matrix)))
## [1] "matrix"

class(reclass(try.xts(sample_matrix)))
## [1] "matrix"

Outras dicas

A call to reclass returns the object to its original class, with all original attributes intact - unless otherwise changed.

From the docs:

Reclass is designed for top-level use, where it is desirable to have the object returned from an arbitrary function in the same class as the object passed in. Most functions within R are not designed to return objects matching the original object’s class. While this tool is highly experimental at present, it attempts to handle conversion and reconversion transparently. The caveats are that the original object must be coercible to xts, the returned object must be of the same row length as the original object, and that the object to reconvert to is the first argument to the function being wrapped.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top