subset in a dataframe

Welcome to the community!

I'll suggest you to create a new column containing number of positive numbers in each row, and then filter based on that.

It'll be something like this:

df_new <- df_old[rowSums(x = df_old > 0, na.rm = TRUE) >= 4,]

I can't test this because you haven't shared the data. If this doesn't solve the problem, can you please provide a REPRoducible EXample of your problem? It provides more specifics of your problem, and it helps others to understand what problem you are facing.

If you don't know how to do it, take a look at this thread:

1 Like