col1 col2
-1 F
2 T
-1 F
-2 F
3 T
when F is selected in col2 I want to find out how many corresponding -ve and +ve values are recorded in col1.
col1 col2
-1 F
2 T
-1 F
-2 F
3 T
when F is selected in col2 I want to find out how many corresponding -ve and +ve values are recorded in col1.
We get the subset of 'col1' values where the 'col2' is "F", get the sign
, count those with table
in base R
with(df1, table(sign(col1[col2 == 'F'])))
Or using dplyr
library(dplyr)
df1 %>%
filter(col2 == 'F') %>%
mutate(col1 = sign(col1)) %>%
count(col1)