Here's a sample data frame.
df = data.frame(company = c('a', 'b', 'c', 'd'),
bond = c(0.2, 1, 0.3, 0),
equity = c(0.7, 0, 0.5, 1),
cash = c(0.1, 0, 0.2, 0))
df
company bond equity cash
1 a 0.2 0.7 0.1
2 b 1.0 0.0 0.0
3 c 0.3 0.5 0.2
4 d 0.0 1.0 0.0
I need to find companies which have 1.0 in any columns. The expected result should be b and d.
Please provide a solution that works for >20 columns.
Solutions like df %>% filter(bond == 1)
only works for searching a particular column.
dplyr
or data.table
solutions are acceptable.
Thanks.