Delete rows in dataframe in R
1
0
Entering edit mode
8.0 years ago
mzezza ▴ 10

Hi,

I have a dataframe with n columns and n rows. I need to search all cells (type string) that starts with "chr......" and I need to delete the corresponding row.

Did you help me ?

Thanks.

R dataframe rows dataframe R • 33k views
ADD COMMENT
2
Entering edit mode
ADD REPLY
1
Entering edit mode

This is more a programming question than bioinformatics...

So if a row contains one element which starts with "chr" the entire row has to be deleted?

ADD REPLY
1
Entering edit mode

I highly recommend the dplyr package by Hadley Wickham: https://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html.

ADD REPLY
1
Entering edit mode

So do I - but it is not especially relevant to this problem.

ADD REPLY
0
Entering edit mode

Fair enough. I thought filter() would easily address the problem but there's no straightforward way of filtering on all columns.

ADD REPLY
0
Entering edit mode

Thanks you all, your advice has been useful. I solved with grepl function.

Now, another question: I need to delete from a dataframe rows of another dataframe (with the same structure) using, maybe, a common cell.

Thanks for your help.

ADD REPLY
0
Entering edit mode

Thanks you all, your advice has been useful. I solved with grepl function.

Now, another question: I need to delete from a dataframe rows of another dataframe (with the same structure) using, maybe, a common cell.

Thanks for your help.

ADD REPLY
0
Entering edit mode

It's advisable to create new threads for new questions. In addition, this is again not a bioinformatics question.

ADD REPLY
3
Entering edit mode
8.0 years ago
newbiebio ▴ 80

If your dataframe name is data, column is cell, try this: data[-grep('chr',data$cell),]

ADD COMMENT
1
Entering edit mode

don't forget "starts with"

ADD REPLY
0
Entering edit mode

just change to:data[-grep("^chr",data$cell,perl=T),]

ADD REPLY

Login before adding your answer.

Traffic: 1593 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6