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

The Archive Base Latest Questions

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

I am a bit puzzled here and must be missing something quite basic. I

  • 0

I am a bit puzzled here and must be missing something quite basic.
I want to extract columns from a multiple time series object. It can perhaps be done by making the ts object into a dataframe and then extracting them, but there is a direct way of subsetting time series as given in this question link

To figure out how to assign names to ts objects, ?ts shows

ts(data = NA, start = 1, end = numeric(), frequency = 1,
   deltat = 1, ts.eps = getOption("ts.eps"), class = , names = )

but on running the code in ?ts help, with or without the names parameter gives
names(z) NULL.

z <- ts(matrix(rnorm(300), 100, 3), start=c(1961, 1), frequency=12)
or z <- ts(matrix(rnorm(300), 100, 3), start=c(1961, 1), frequency=12, names=c("x1", "x2", "x3"))

Main question: 1. How does one assign names to columns in time series objects ts and mts ?
2. What are the methods of extracting columns directly from time series object along with the time index? Is it necessary to convert it to zoo or xts class? or add the time index separately?

To give an idea of problem I am trying to solve:

# using inbuilt ldeaths time series dataset
ldeaths
d <- diff(ldeaths)
percen <- quantile(d, 0.9)
i <- ifelse(d>percen, 1,0)
signal <- cbind(d,i) 

Now to extract the dataset for which the indicator is 1, with the time index,
I am not sure how to proceed. str(signal) is an mts object but printing signal shows no time index.

Thanks a lot.

  • 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-13T23:08:36+00:00Added an answer on June 13, 2026 at 11:08 pm

    Extracting the names of series in an "mts" object

    You want colnames():

    > colnames(z)
    [1] "x1" "x2" "x3"
    

    This is because z is actually a matrix with extra attributes and matrices don’t have names but they do have colnames.

    Assigning/changing the names of series in an "mts" object

    To assign colnames after the fact or to change them use the replacement function 'colnames<-'

    > colnames(z) <- paste0("a", 1:3)
    > colnames(z)
    [1] "a1" "a2" "a3"
    

    Extracting a particular series from an "mts" object

    As for extracting columns, [ works just fine for "ts" and "mts" objects. for example:

    > z[,1]
                 Jan         Feb         Mar         Apr         May
    1961  0.81800833 -0.30852155  0.05915071  0.14937058  0.67734362
    1962  1.12993606 -0.81176485 -0.51903387  1.12527537 -0.34377553
    1963  1.30469813  0.32486340  0.01029512 -1.13631688 -1.22013150
    1964  0.72449621 -0.88704234  0.78834391 -0.92956537 -0.31584252
    1965  0.24610412  0.97980266  0.17136276  2.45216318  0.15846038
    1966 -0.48891587 -0.62820331  0.33190472  2.14094813  1.32389152
    1967  0.49120472 -0.10149521 -0.39070688 -0.78743955 -1.20563040
    1968 -0.70749150  0.52333087 -0.51991721  0.02037504 -0.59848254
    1969 -0.80156968 -1.38172513  0.09400527  0.66966443            
    ....
    

    The guts of the OP’s problem

    For the last bit, I’m not sure what you hope to get. A "ts" or "mts" object is a regular time series and extracting the bits of signal[, "d"] results in a vector not a time series.

    > signal[signal[,2] == 1, 1]
    [1]  761 1104  810  653  522  956  593
    

    There isn’t any time index because this is no longer a "ts" object. If you want to do this, the zoo package is probably the way you want to go. Here is an example, where we convert to zoo object using as.zoo()

    require(zoo)
    sz <- as.zoo(signal)
    

    Then we can extract the observations we want (the names on which are a useful indicator of the time index)

    > sz[sz[, "i"] == 1, "d"]
    1975(12)  1976(2) 1976(12) 1977(12)  1978(1) 1978(12)  1979(1) 
         761     1104      810      653      522      956      593 
    

    and then a similar subsetting call but using the index() to return the time index of the entire zoo object and then select out the bits we want

    > index(sz)[sz[, "i"] == 1]
    [1] 1975.917 1976.083 1976.917 1977.917 1978.000 1978.917
    [7] 1979.000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit puzzled to something we got here at the office. We have
I'm a bit puzzled: From Cocoa Programming For Mac OS X (page 63, 3rd
I'm a bit puzzled and I believe I might missing some configuration, or perhaps
I am a bit puzzled over how to send a file from an http
I am a little bit puzzled as to how I can optimize my program
I am a bit puzzled with my Regex results (and still trying to get
I am a bit puzzled by this strange behavior on CentOs 5.4 when starting
I'm a bit puzzled about the conditional operator. Consider the following two lines: Float
I'm updating samples/c/motempl.c to OCV 2.3 and I'm a bit puzzled by the cv::updateMotionHistory()
I'm doing simple divisions in c#, and I am a bit puzzled by its

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.