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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:06:38+00:00 2026-05-30T07:06:38+00:00

This is a very simple question. I have a lengthy dataset and want to

  • 0

This is a very simple question.

I have a lengthy dataset and want to create a subset based on certain entries in a particular column. In this case, I am setting it up like this:

Example data:

> NL

SNP alleles

rs1234 A_T

rs1235 A_G

rs2343 A_T

rs2342 G_C

rs1134 C_G

rs1675 T_A

rs8543 A_T

rs2842 G_A

P <- subset(NL, alleles = "A_T", alleles = "T_A", alleles = "G_C", alleles = "C_G")

This runs without error, but the resulting P is not subset in any way (tail of P still shows same number of entries as original NL).

What am I doing wrong?

  • 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-05-30T07:06:39+00:00Added an answer on May 30, 2026 at 7:06 am

    The most obvious error is using “=” when you mean”==”. But I’m guessing from context that you really want to “split” this data:

    split(NL, NL$alleles)
    

    Which will create a list of dataframes each of which has one of the values for alleles.

    But perhaps you do want to use pattern matching:

    NL[ grepl("C_G|G_C|A_T|T_A", NL$alleles), ]
         SNP alleles
    1 rs1234     A_T
    3 rs2343     A_T
    4 rs2342     G_C
    5 rs1134     C_G
    6 rs1675     T_A
    7 rs8543     A_T
    

    And illustrating with what I think was your comment-example:

    P <- read.table(text="V1 V2 V3 V4 V5 V6 alleles
     15116 25 rsX 0 123412 G A G_A 
    15117 25 rsX1 0 23432 A C A_C 
    15118 25 rsX2 0 234324 A G A_G 
    15119 25 rsX3 0 3423 A G A_G 
    15120 25 rsX4 0 2343223 C A C_A 
    15121 25 rsX5 0 23523423 A G A_G", header=TRUE)
    
     P[ grepl("G_A", NL$alleles), ]
    
    #       V1       V2 V3        V4 V5 V6 alleles
    # 15116 25 rs306910  0 154613671  G  A     G_A
    

    The subset version:

     subset(P, alleles %in% c("G_A", "A_G") )
    
          V1   V2 V3       V4 V5 V6 alleles
    15116 25  rsX  0   123412  G  A     G_A
    15118 25 rsX2  0   234324  A  G     A_G
    15119 25 rsX3  0     3423  A  G     A_G
    15121 25 rsX5  0 23523423  A  G     A_G
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a very simple question yet I have little knowledge in Linux and
i have a very simple question, actually this is not the question, this is
This may seem a very silly question. Consider this: I have a simple Boolean
This is a very simple question. I have a Html.helper: @Html.DisplayFor(modelItem => item.Text) How
I have a very simple Ruby question. Is there a way to refactor this:
This is a very simple question, but I can't seem to find something about
This is a very simple question and I feel stupid for asking it, but
This may be very simple question,But please help me. i wanted to know what
This should be very simple question. There are many programming languages out there, compiled
I'm sure this is a very simple question, but embarrassed to say I can't

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.