Remove rows according to total number values

Hello everyone,

I am pretty new in the R World. I am wondering whether remove the rows according to the total number of them. I examined the cheat sheet of dplyr and some examples on the internet. All of them were concerned with single values on rows/columns.

My samples look as follows (normally I have matrix sized 212x 390 ):


So what I want to do: If the total number of each gene on the rows is less than 10, for example, the row must remove.

for (number in seq(4)) {
    if (sum(mymat[number,])< 10){
      mymat<- mymat[-number,]

Well, the code I wrote works end of the day. But, I would like to perform with dplyr package.

Which dplyr function I should use?

Thank you in advance,

Here is a way

(myex <- tibble(
  a = 4:5,
  b = 5:6

myex |>
  rowwise() |>
  filter(sum(c_across(cols = where(is.numeric)))
         >= 10)
1 Like

Base R:

df <- df[which(rowSums(df)>=10), ]

1 Like

Thank you nirgrahamuk and fcas80.

Both of them seem perfect!

Thank you for your help.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.