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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:24:00+00:00 2026-06-12T21:24:00+00:00

I have the following data frame from which I would like to extract rows

  • 0

I have the following data frame from which I would like to extract rows based on matching strings.

> GEMA_EO5
gene_symbol  fold_EO  p_value                           RefSeq_ID      BH_p_value
       KNG1 3.433049 8.56e-28              NM_000893,NM_001102416    1.234245e-24
      REXO4 3.245317 1.78e-27                           NM_020385    2.281367e-24
      VPS29 3.827665 2.22e-25                 NM_057180,NM_016226    2.560770e-22
    CYP51A1 3.363149 5.95e-25              NM_000786,NM_001146152    6.239386e-22
      TNPO2 4.707600 1.60e-23 NM_001136195,NM_001136196,NM_013433    1.538000e-20
      NSDHL 2.703922 6.74e-23              NM_001129765,NM_015922    5.980454e-20
     DPYSL2 5.097382 1.29e-22                           NM_001386    1.062868e-19

So I would like to extract e.g. two rows based on matching strings in $RefSeq_ID, that works fine with the following:

> list<-c("NM_001386", "NM_020385")
> GEMA_EO6<-subset(GEMA_EO5, GEMA_EO5$RefSeq_ID %in% list, drop = TRUE)

> GEMA_EO6

gene_symbol  fold_EO  p_value RefSeq_ID    BH_p_value
      REXO4 3.245317 1.78e-27 NM_020385  2.281367e-24
     DPYSL2 5.097382 1.29e-22 NM_001386  1.062868e-19

But some of the rows have several RefSeq_IDs separated with commas, so I am looking for a general way of telling if $RefSeq_ID contains a certain string pattern and then subset that row.

  • 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-12T21:24:01+00:00Added an answer on June 12, 2026 at 9:24 pm

    To do partial matching you’ll need to use regular expressions (see ?grepl). Here’s a solution to your particular problem:

    ##Notice that the first element appears in 
    ##a row containing commas
    l = c( "NM_013433", "NM_001386", "NM_020385")
    

    To test one sequence at a time, we just select a particular seq id:

    R> subset(GEMA_EO5, grepl(l[1], GEMA_EO5$RefSeq_ID))
      gene_symbol fold_EO p_value                           RefSeq_ID BH_p_value
    5       TNPO2   4.708 1.6e-23 NM_001136195,NM_001136196,NM_013433  1.538e-20
    

    To test for multiple genes, we use the | operator:

    R> paste(l, collapse="|")
    [1] "NM_013433|NM_001386|NM_020385"
    R> grepl(paste(l, collapse="|"),GEMA_EO5$RefSeq_ID)
    [1] FALSE  TRUE FALSE FALSE  TRUE FALSE  TRUE
    

    So

    subset(GEMA_EO5, grepl(paste(l, collapse="|"),GEMA_EO5$RefSeq_ID))
    

    should give you what you want.

    • 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
SQLDF newbie here. I have a data frame which has about 15,000 rows and
I have a file, called genes.txt , which I'd like to become a data.frame.
I am trying create a data.frame from which to create a graph. I have
Suppose I have the following data frame: Data1 X1 X2 1 15 1 2
I have the following data.frames: a <- data.frame(id = 1:3, v1 = c('a', NA,
I have the following data: a=c(1:10) b=c(16:25) c=c(24:33) wa=c(3,7,3,3,3,3,3,3,3,1) wb=c(3,2,3,3,3,3,3,3,3,8) wc=c(4,1,4,4,4,4,4,4,4,1) z=data.frame(a,b,c,wa,wb,wc) I want
I have the following dataframe: DF <- data.frame(x = c(1, 2, 3,NA), y =
I have the following dummy code: dt<-data.frame(country=letters[1:20],val=rnorm(20),siz=rnorm(20)) qplot(x=country,y=val,data=dt,geom=point,size=siz) Now I want to increase the
I have the following dataframe: sp <- combn(c(sp1,sp2,sp3,sp4),2) d <- data.frame(t(sp),freq=sample(0:100,6)) and two factors

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.