This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Delete rows in dataframe in R

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

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?

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

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

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.

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.

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

1 answer

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

don't forget "starts with"

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

Log in to answer this question.