Question: Extracting rows on basis of specific column values in R
0
gravatar for sidrah.maryam
6 months ago by
sidrah.maryam30 wrote:

I have a dataframe that contains various fields. An instance being:

Protein Code Sequence CODON XYZ L AATTGCTA MET ABC K ATTGCTA MET-2 JKL B GCTTATA LYS-2

I want to extract information of all the elements in which the column CODON ends with "-2".

Like in this case i get : ABC K ATTGCTA MET-2 JKL B GCTTATA LYS-2

Please suggest the answer.

I used :

od_lig <- filter(odor_lig, CODON== "$-2")

But I got blank data.

datasets dataframe python R • 251 views
ADD COMMENTlink modified 6 months ago by Shalu Jhanwar490 • written 6 months ago by sidrah.maryam30

Because you are using a regular expression and filter doesn't understand regex directly. Wrap your regex in grepl and also give it the target column and wrap that in your filter function.

ADD REPLYlink written 6 months ago by rezaeir7510

please work through any of the many online R tutorials. You could also look up "how to ask questions" and unfortunately it looks like a correct tagging of posts tutorial is also necessary. Maybe you think the $ would signify a regex end matching? try endsWith

ADD REPLYlink written 6 months ago by Ido Tamir5.1k

What does a value in the CODON column actually look like?

ADD REPLYlink written 6 months ago by rpolicastro4.0k
1
gravatar for Shalu Jhanwar
6 months ago by
Shalu Jhanwar490
Switzerland
Shalu Jhanwar490 wrote:

Suppose the entire protein Code Sequence is read in one column (codon) of the data frame. You can use the below code in R script to extract rows ends with "-2":

grepl("-2$",df$codon)
ADD COMMENTlink modified 6 months ago • written 6 months ago by Shalu Jhanwar490

Thank you so much for your help

ADD REPLYlink written 5 months ago by sidrah.maryam30
1

If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they work. This will help future users that might find this post find the right answer.

Upvote|Bookmark|Accept

ADD REPLYlink written 5 months ago by Ram32k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2251 users visited in the last hour
_