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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:46:29+00:00 2026-06-07T18:46:29+00:00

Does anyone have a suggestion on how to extract columns from a data set

  • 0

Does anyone have a suggestion on how to extract columns from a data set based on metadata stored in a second data set? Just wondering if there is a relatively straightforward way (e.g. using “colnames” or “subset”). My original data set is quite large with more than 100 columns and more than 30,000 rows. Opening the file and selecting in Excel is a pain.

Here two example data sets:

set1 <- data.frame(ID = rnorm(5, 5000, 1000), Sample1 = rnorm(5, 50000, 2500), 
Sample2 = rnorm(5, 50000, 2500), Sample3 = rnorm(5, 50000, 2500), 
Sample4 = rnorm(5, 50000, 2500), Sample5 = rnorm(5, 50000, 2500))

meta.data <- data.frame(Sample_name = c("Sample1", "Sample2", "Sample3", 
"Sample4", "Sample5"), Location = c("Loc1", "Loc2", "Loc3", "Loc1", "Loc1"), 
Time = c("M0", "M01", "M02", "M02", "M03"), 
Conc = c("lo", "hi", "lo", "lo", "lo"))

(1) How could I extract (as a new data set) all samples from Location Loc1 or all samples from Time M02?

(2) How could I extract a row that has a certain ID number and select only those samples within that row that have a Conc “lo”?

  • 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-07T18:46:31+00:00Added an answer on June 7, 2026 at 6:46 pm

    Not sure if this is the best way, with a merge possibly being more appropriate, but here is how to do some subsetting:

    (1) How could I extract (as a new data set) all samples from Location Loc1…

    #get a list of the samples all from Location Loc1
    as.character(meta.data$Sample_name[meta.data$Location=="Loc1"])
    #use this list of samples to subset the set1 data
    set1[c("ID",as.character(meta.data$Sample_name[meta.data$Location=="Loc1"]))]
    
            ID  Sample1  Sample4  Sample5
    1 3836.499 53304.29 47720.79 49504.96
    2 4620.443 49406.93 49123.49 50419.93
    3 5614.903 44413.93 50387.27 48652.29
    4 6676.880 52732.63 48282.92 53544.17
    5 3926.077 52593.59 50204.96 49563.13
    

    (2) How could I extract a row that has a certain ID number and select only those samples within that row that have a Conc “lo”?

    I’ve just used set1$ID[1] as a replacement for a selected ID here due to the example being random numbers. Just replace it with something like set1$ID=="idnum1"

    subset(set1,set1$ID==set1$ID[1])[c("ID",as.character(meta.data$Sample_name[meta.data$Conc=="lo"]))]
    
            ID  Sample1  Sample3  Sample4  Sample5
    1 3836.499 53304.29 49706.58 47720.79 49504.96
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a VB.Net data set that contains data from multiple tables. Does anyone
Does anyone have a suggestion on a better way to intercept a properties with
Does anyone have a suggestion for creating paragraph-type line spaces within a <li> tag
Does anyone have a suggestion on how to create a system that allows me
Does anyone have a suggestion for where to find archives or collections of everyday
Does anyone have a suggestion for a replacement to Coda Slider 2.0 ? While
Does anyone have good suggestion of the best option for jQuery Ajax to refresh
Does anyone have a suggestion regarding tidying up the following code: /* Example code
Does anyone have any suggestions on how to edit an <a href=''> link in
Does anyone have a suggestions for a superb cool image gallery that I can

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.