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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:41:35+00:00 2026-06-13T17:41:35+00:00

I would like to generate a list of time series based on the column

  • 0

I would like to generate a list of time series based on the column indexs of a master time series (m)

head(cols)
          [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18]
    [1,]    1    1    1    1    1    1    1    1    1     1     1     1     1     1     1     1     1     1
    [2,]    2    2    2    2    2    2    2    2    2     2     2     2     2     2     2     2     2     2
    [3,]    3    3    3    3    3    3    3    3    4     4     4     4     4     4     4     5     5     5
    [4,]    4    5    6    7    8    9   10   11    5     6     7     8     9    10    11     6     7     8

so for example the first data.frame in the list would be made from m[,1], m[,2], m[,3] and m[,4] and look something like

              1            2             3            4   
2012-01-01 -0.0248361511  0.0127908458 -0.011976191  0.009987137
2012-01-02 -0.0005351887  0.0290350115  0.004208001  0.007078312
2012-01-03 -0.0016072867  0.0042660695  0.008660648 -0.018255748
2012-01-04  0.0016072867 -0.0001303243  0.001782532 -0.004775416
2012-01-05  0.0026730837 -0.0038740336 -0.007149271  0.015511091

And the 14th would be something like

              1            2             4            10
2012-01-01 -0.0248361511  0.0127908458  0.009987137  0.0051973431
2012-01-02 -0.0005351887  0.0290350115  0.007078312  0.0081517268
2012-01-03 -0.0016072867  0.0042660695 -0.018255748 -0.0008121889
2012-01-04  0.0016072867 -0.0001303243 -0.004775416  0.0071366761
2012-01-05  0.0026730837 -0.0038740336  0.015511091  0.0186782999

is there some function I can write or use in the form

apply(cols,2, function(x)  DOSOMETHINGLIKE"a <- merge(a,m[x])"HERE)
  • 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-13T17:41:37+00:00Added an answer on June 13, 2026 at 5:41 pm
    1. Some sample data:

      set.seed(1)
      setRmetricsOptions(myFinCenter = "GMT")
      charvec = timeCalendar()
      TS <- as.timeSeries(matrix(rnorm(60), ncol = 5), charvec)
      head(TS)
      # GMT
      #                  TS.1        TS.2        TS.3       TS.4       TS.5
      # 2012-01-01 -0.6264538 -0.62124058  0.61982575 -0.3942900 -0.1123462
      # 2012-02-01  0.1836433 -2.21469989 -0.05612874 -0.0593134  0.8811077
      # 2012-03-01 -0.8356286  1.12493092 -0.15579551  1.1000254  0.3981059
      # 2012-04-01  1.5952808 -0.04493361 -1.47075238  0.7631757 -0.6120264
      # 2012-05-01  0.3295078 -0.01619026 -0.47815006 -0.1645236  0.3411197
      # 2012-06-01 -0.8204684  0.94383621  0.41794156 -0.2533617 -1.1293631   
      
    2. Verify the class of the data to see that it is not a standard data.frame:

      class(TS)
      # [1] "timeSeries"
      # attr(,"package")
      # [1] "timeSeries"
      
    3. Make a sample matrix from which we will be selecting the columns from the TS object created above:

      GetMe <- replicate(3, sample(5, 3))
      GetMe
      #      [,1] [,2] [,3]
      # [1,]    5    1    3
      # [2,]    2    4    1
      # [3,]    4    2    4
      
    4. Use lapply to subset according to the column-wise values from the above matrix:

      myList <- lapply(1:ncol(GetMe), function(x) TS[, GetMe[, x]])
      myList[[1]] # View one of the resulting subsetted data
      # GMT
      #                  TS.5        TS.2       TS.4
      # 2012-01-01 -0.1123462 -0.62124058 -0.3942900
      # 2012-02-01  0.8811077 -2.21469989 -0.0593134
      # 2012-03-01  0.3981059  1.12493092  1.1000254
      # 2012-04-01 -0.6120264 -0.04493361  0.7631757
      # 2012-05-01  0.3411197 -0.01619026 -0.1645236
      # 2012-06-01 -1.1293631  0.94383621 -0.2533617
      # 2012-07-01  1.4330237  0.82122120  0.6969634
      # 2012-08-01  1.9803999  0.59390132  0.5566632
      # 2012-09-01 -0.3672215  0.91897737 -0.6887557
      # 2012-10-01 -1.0441346  0.78213630 -0.7074952
      # 2012-11-01  0.5697196  0.07456498  0.3645820
      # 2012-12-01 -0.1350546 -1.98935170  0.7685329
      
    5. Verify the classes of the objects in this list:

      lapply(myList, class)
      # [[1]]
      # [1] "timeSeries"
      # attr(,"package")
      # [1] "timeSeries"
      # 
      # [[2]]
      # [1] "timeSeries"
      # attr(,"package")
      # [1] "timeSeries"
      # 
      # [[3]]
      # [1] "timeSeries"
      # attr(,"package")
      # [1] "timeSeries"
      
    6. In the future please provide a reproducible example and be specific in your question about what you are actually working with (for example, which packages you have used to create your data, what is currently loaded, and so on). Your question clearly states you are working with data.frames, but your comment to my original answer reveals you’re actually working with a timeSeries object from the timeSeries package which requires a (slightly) different approach.

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

Sidebar

Related Questions

I would like for the generate List view contents to have a check added
I would like to generate a combination of words. For example if I had
I would like to generate a list of all the files that have been
I would like to generate a patch with all commits from a local branch.
I would like to generate POJO, XML for a given database. Database: ( contents
i would like to generate a very simple report with some images and text
I would like to generate a short, unique ID without having to check for
I would like to generate a graphical sitemap for my website. There are two
I would like to generate the mysql-password hash from js. I know the method
I would like to generate a regex for a string like S67-90. I used

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.