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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:28:59+00:00 2026-06-10T16:28:59+00:00

I have a matrix of data with column and row names, as such: Col1

  • 0

I have a matrix of data with column and row names, as such:

     Col1  Col2  Col3 ...
Row1 0.1   0.2   0.4  ...
Row2 1.8   13.1  0.2  ...
Row3 8.0   9.2   9.1  ...
...  ...   ...   ...

And I have an object with multiple lists of subsets of column titles, as such:

$list1
 [1] "Col1"       "Col2"      "Col13"     "Col56"     "Col267"    "Col300"
 [7] "Col301"     

$list2
 [1] "Col4"       "Col6"      "Col7"      "Col54"     "Col199"     "Col203"

...

I would like to grab a subset of the original matrix with only the columns from each list. It seem like I can do it if I specify the column titles explicitly, e.g.:

example.matrix[,c("Col4","Col6","Col7","Col54","Col199","Col203")]

But if I make a data object matching that character vector it doesn’t work:

test <- as.character(example.col_list[1])
          #^this prints to terminal as 
          #"c("Col4","Col6","Col7","Col54","Col199","Col203")" 
example.matrix[,test]

This gives an Error: subscript out of bounds. After playing around with variations on this, using the subset function, trying to find indices of the columns (using which and match functions), nothing seems to work. It all seems to hinge on not being able to interpret each list of column names as I think it should. I know I am likely missing something simple but it is difficult to find an answer on SO or Google search after long effort, Any ideas?

If it helps, I am doing this to make a figure for each of the subsets of columns and there are ~10k subsets so it is not feasible to do a manual workaround. I need to nest this is a loop or within a function somehow. Thanks!

  • 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-10T16:29:01+00:00Added an answer on June 10, 2026 at 4:29 pm

    You don’t want to construct an R call that gets put into “[” as a character string that would then need to get parsed and evaluated. You want to put an object that is a character vector itself. Try this:

    test <- example.col_list[[1]]  # note "[[" instead of "["
    
    example.matrix[ , test]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a matrix of data (with row names and column names). I would
I have an m x n Matrix, which I call data. The last column
I have a matrix where the first column contains dates and the first row
I have a matrix of data (the columns represent time, and the rows spectrum
I have a matrix of data, m : 12345 12348 2011-05-13 NA 0.18001079 2011-05-16
Suppose I have a matrix of weights, and another matrix of data values. Can
I have a matrix of objects that contains data in this form: name A,2,name
I have a matrix A which I want to convert into a data.frame of
I have a data set which consists of an ID and a matrix (n
Is there a way to concatenate the row and column names from an existing

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.