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

  • SEARCH
  • Home
  • 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 6690915
In Process

The Archive Base Latest Questions

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

Hi my xts structure is : head(sym) BidSize Bid Ask AskSize Quantity Mid 2006-01-04

  • 0

Hi my xts structure is :

head(sym)

                     BidSize  Bid  Ask    AskSize Quantity Mid
   2006-01-04 09:01:00    3771 181000 182000    5783    15625 181500
   2006-01-04 09:02:00    3952 181000 182000    5659      180 181500
   2006-01-04 09:03:00    3556 181000 182000    5943     1059 181500
   2006-01-04 09:04:00    3747 181000 182000    6133      261 181500
   2006-01-04 09:05:00    3957 181000 182000    6077      101 181500
   2006-01-04 09:06:00    3898 181000 182000    6511      311 181500

I have a function getTickSize(x,date) which is designed for x as a single numeric (not an array).

I would like if possible to replace the following for loop by a “smart” call to the apply family of functions

for (i in 1:nrow(sym[1:10])){
    sym$TS[i] <- getTickSize(sym$Mid[i],index(sym)[i])
  }

Any pointer ? all my attempts were met with the following warnings:

    the condition has length > 1 and only the first element will be used 
  • 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-26T05:41:29+00:00Added an answer on May 26, 2026 at 5:41 am

    I believe in this case, mapply is the easiest solution:

    sym$TS<-mapply(getTickSize, sym$Mid, index(sym))
    

    Note: the *apply family of functions is not always better than a simple loop (most of the myth around that dates way back to early version of S).

    But I admit it looks a lot sexier.

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

Sidebar

Related Questions

I have an xts object that has intraday data: head(stocks[,1]) SMH.close 2009-01-02 09:31:00 17.66
I have three vectors in an xts R object. Call them V1, V2, V3.
I have a structure for a tree and I want to print the tree
Assume: list of n xts objects in .GlobalEnv with the suffix .raw (e.g: ABC.raw
I have an xts object, the first column of which is date-time, followed by
I have an XTS timeseries in R of the following format and am trying
I've found some information about xts fields representation in this thread but I'm still
How do I subset an xts object to only include weekdays (Mon-Fri, with Saturday
Is there a workaround to set the color when using plot.xts ? This bug
I have a df/zoo/xts/whatever that is split by day of week. I'd like to

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.