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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:46:22+00:00 2026-05-23T20:46:22+00:00

x is an xts object full of data; let’s assume OHLC data for the

  • 0

x is an xts object full of data; let’s assume OHLC data for the sake of example.
I want to create another xts object, with the same size and datestamps, but different columns (e.g. some indicators).

My current approach feels crude:

a = x$close
for(nn in 1:10){
    z = analysis(x,nn) #Returns an enhanced version of x
    z2 = z$result   #Get out just the data I want, so I can rename the column
    colnames(z2) = paste("result",nn,sep="_")
    a = cbind(a,z2) #Merge in each result
    }
a$close = NULL  #Tidyup

I.e. I bring in just one column from x, any old column, just to get the structure, then throw that away at the end. (It works, so I’m happy, but it feels like there must be a better way.)

I tried some ideas like this:

a = xts(index(x))
a = xts(orderby=index(x))
a = as.xts(index(x))
a = as.xts(orderby=index(x))

But they give me empty XTS objects. E.g. when I then try this I get an error:

a$dummy = 1
  • 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-23T20:46:23+00:00Added an answer on May 23, 2026 at 8:46 pm

    Note the argument is order.by, not orderby. That doesn’t solve your issue though. What you’re looking for is:

    a <- xts(order.by=index(x))
    a <- merge(a, dummy=1)
    

    a$dummy <- 1 doesn’t work because zoo objects can be a vector or a matrix, while xts objects are always a matrix and there’s no $<-.xts method.

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

Sidebar

Related Questions

Is there a way to create an xts object from a data.frame and preserve
I have an xts object that has intraday data: head(stocks[,1]) SMH.close 2009-01-02 09:31:00 17.66
I have some imported csv data that I have turned into an xts object.
I have one main XTS object Data with ~1M rows spanning 22 days. I
I have an xts object, for example ts=xts(seq(10),seq(Sys.Date(),Sys.Date()+10,length.out=10)) and need to add a new
I have an xts object, x. I want to run a for loop until
First I read-in a csv and create an xts object. require(quantmod) sugar <- as.xts(read.zoo(SUGAR.CSV,
I have three vectors in an xts R object. Call them V1, V2, V3.
I have an xts object, the first column of which is date-time, followed by
How do I subset an xts object to only include weekdays (Mon-Fri, with Saturday

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.