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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:48:22+00:00 2026-06-07T22:48:22+00:00

I have the following test data frame : test <- read.table(header = TRUE, text

  • 0

I have the following test data frame :

test <- read.table(header = TRUE, text = "
    a      b      c      d      e
-0.67  -0.02  -0.1   -0.22  -0.32
 0.46  -1.51  -0.79   0.26   1.19
 0.22  -0.18  -1.4    0.41  -0.32
-2.21   0.79   0.36   1.    -0.51
-0.69   0.39  -0.76  -0.73  -0.43
-0.45  -1.33   0.15  -2.23  -0.58
")

In this format, I can easily access the columns using the test$b notation. I can convert this to a time series object without difficulty:

test.ts <- ts(test, frequency=<value>, start=<value>

However, once it’s a ts object, is there any easy way to access the columns (or rows) by name instead of by column number? The test.ts object still has the column name information, shown by using colnames:

> colnames(test.ts)
[1] "a" "b" "c" "d" "e"

However, test.ts$b doesn’t work. Note that by "easily" I mean without writing something ugly like test.ts[,which(colnames(test.ts)=="b"], because that’s not easy, that’s ugly. Yes, I could write my own function to do that, but I was wondering whether there’s a built-in way to do this.

  • 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-07T22:48:26+00:00Added an answer on June 7, 2026 at 10:48 pm

    Use the other subsetting syntax:

    test.ts[, 'b']
    #Time Series:
    #Start = 1 
    #End = 6 
    #Frequency = 1 
    #[1] -0.02 -1.51 -0.18  0.79  0.39 -1.33
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data test<-data.frame(group=1:10, var.a=rnorm(n=10,mean=500,sd=20), var.b=runif(10)) I would like a barplot with
I have the following test code use Data::Dumper; my $hash = { foo =>
I have the following data in my database (comma separated strings): word, test, hello
Let say I have the following data in R. training = factor(c(1,1,3,2,1,3,2,34,67,34)) test =
I have a data frame which can be generated with: a <- c(rep(w,3), rep(x,3),
I have the following xslt to transform data into a JQuery-accepted format. However, because
I have some data (E.g.: 'acs24','45','ds' etc). Using this data I have the following
I have the following table: create table test ( fname char(20) character set utf8
This example is simplified. I have the following design: http://img835.imageshack.us/i/designyi.jpg/ I have inserted test
Suppose I have the following data frame > df <- data.frame(var1 = c(A, B,

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.