Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8633177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:27:14+00:00 2026-06-12T09:27:14+00:00

Why does myclass disapear in the following example? How to avoid that? # library(xts)

  • 0

Why does “myclass” disapear in the following example?
How to avoid that?

#
library(xts)

# sample data
fo <- "%Y-%m-%d %X"
st <- Sys.time()
delta <- seq(from=0, by=10, length.out=10)
ma1 <- matrix(data=sin(delta/50), ncol=1, nrow=10)
ma2 <- matrix(data=sin(delta/25), ncol=1, nrow=10)
d1a <- xts(x=ma1, order.by=strptime(st, format=fo) + delta)
d2a <- xts(x=ma2, order.by=strptime(st, format=fo) + delta)
d1b <- xts(x=ma1, order.by=strptime(st, format=fo) + delta)
d2b <- xts(x=ma2, order.by=strptime(st, format=fo) + delta)
d1c <- xts(x=ma1, order.by=strptime(st, format=fo) + delta)
d2c <- xts(x=ma2, order.by=strptime(st, format=fo) + delta)

# original class
class(d1a)
class(d2a)
#
d3a <- d1a + d2a

# class
class(d1b) <- "myclass"
class(d2b) <- "myclass"
#
d3b <- d1b + d2b

# class
class(d1c) <- c("myclass","xts","zoo")
class(d2c) <- c("myclass","xts","zoo")
#
d3c <- d1c + d2c

#
class(d3a)
[1] "xts" "zoo"
class(d3b)
[1] "myclass"
class(d3c)
[1] "xts" "zoo" # expected was "myclass" "xts" "zoo"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:27:15+00:00Added an answer on June 12, 2026 at 9:27 am

    EDIT: This is fixed in xts > 0.12.2

    Now Ops.xts() retains the class of the objects that inherit from xts.

    class(d3c)
    [1] "myclass" "xts"     "zoo"
    

    You haven’t defined a + method for myclass, so the xts method gets dispatched… and it always returns an xts-class object (unfortunately).

    You can work around this by defining:

    Ops.myclass <- xts:::Ops.xts
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does one do this in c#? Let's say that myclass has : private
I have a symbol that appears that is listed as MyNamespace.MyClass.<.ctor>b__8() What exactly does
I have a method that looks similar to the following: public void myMethod(MyClass c)
Does PHP versions 5.3 or after support inner classes? example: class MyClass{ class PrivateClass1{
i have a function that does this: static MyClass* MyFunction(myparams) { return new MyClass(myparams)
What does the following code do? class MyClass { private int[] myPrivates; public int[]
How does the code looks that would create an object of class: string myClass
I have a class that does something like: class MyClass(object): def __init__(self, delegate_to): self._delegate_to
If I have a class called myclass does having static methods within the class
Look at this code: class MyClass(): # Why does this give me NameError: name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.