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 6665133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:41:27+00:00 2026-05-26T02:41:27+00:00

I am working with some code that uses the %*% operator to apply vectors

  • 0

I am working with some code that uses the %*% operator to apply vectors of weights to vectors representing time series. I would like to use xts for the time series, but the %*% operator is not understanding that it should ignore the xts index values.

I know I can use coredata() to pull out my series values as a vector, operate on the values, and merge them back in, but I was wondering whether there was a good native xts function I should be using.

EDIT: code sample illustrating the difference I’m seeing in behavior.

library(xts)
data(sample_matrix)
s<-as.xts(sample_matrix)

o_xts<-s$Open
c_xts<-coredata(s$Open)

len <-length(c_xts)
len2<-len/2
xx<-c_xts[1:len]
outp<-0*0:len2
outp[2] <- xx%*%exp((1:(2*len2))*1.i*pi/len2)
#completes without issue

len <-length(o_xts)
len2<-len/2
yy<-o_xts[1:len]
outp<-0*0:len2
outp[2] <- yy%*%exp((1:(2*len2))*1.i*pi/len2)
Warning message:
In outp[2] <- yy %*% exp((1:(2 * len2)) * (0+1i) * pi/len2) :
  number of items to replace is not a multiple of replacement length
  • 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-05-26T02:41:27+00:00Added an answer on May 26, 2026 at 2:41 am

    If you check help("[.xts") you’ll notice that drop defaults to FALSE. For ordinary matrices the default is TRUE.

    str(o_xts[1:len])
    # An ‘xts’ object from 2007-01-02 to 2007-06-30 containing:
    #   Data: num [1:180, 1] 50 50.2 50.4 50.4 50.2 ...
    #  - attr(*, "dimnames")=List of 2
    #   ..$ : NULL
    #   ..$ : chr "Open"
    #   Indexed by objects of class: [POSIXct,POSIXt] TZ: 
    #   xts Attributes:  
    #  NULL
    
    str(c_xts[1:len])
    # num [1:180] 50 50.2 50.4 50.4 50.2 ...
    

    That means that your xx is a 180 element vector whereas your yy is a 180 x 1 matrix. To get the same behaviour in both cases you could use yy <- o_xts[1:len, drop=TRUE].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on some code that uses the System.Diagnostics.Trace class and I'm wondering how
I'm working with some code that widely uses the idiom of returning a pointer
I have been working on some legacy C++ code that uses variable length structures
I have some working code that uses IImgCtx to load images, but I can't
I am working with some code that uses an OleDbConnection to load data from
I'm working with legacy code that uses some convoluted logic to bind IN and
I have some PHP code in a project I'm working on that uses PHP's
I'm working on some code that uses Open Dynamics Engine . I've worked with
I'm working on some C++ code that uses libsigc++ for signaling (eventing.) I'm quite
I am working on editing some old C++ code that uses global arrays defined

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.