Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discard value=1 across entire row

Rows where all the values are 1. I wish to remove all such rows.

like image 271
80907 Avatar asked Nov 16 '25 03:11

80907


1 Answers

Calling your data df,

df[rowSums(df == 1) < ncol(df), ]

rowSums(df == 1) is the count of 1s in each row. We keep rows where that is strictly less than the number of columns.

like image 84
Gregor Thomas Avatar answered Nov 17 '25 18:11

Gregor Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!