having a tibbl df:
A B C
1 0 -1
2 1 2
-3 -2 1
I need to filter all columns based on a condition and summarize them to a new variable (I know the legth is different then, but is there an else option for "NA"?
I know it works when I sum them or min/max etc. Summarize all group values and a conditional subset in the same call
df %>% summarise(A_to_B = (A[A < 0]),
B_to_A = (A[A > 0]),
B_to_C = (B[B < 0]),
C_to_B = (B[B > 0]),
C_to_B = (C[C < 0]),
B_to_C = (C[C > 0]))
Hope it is clear what I mean, I want to sort a variable to a new one, if it doesn't fit to the condition it should be NA to have the same length for a resulting tibble/df.
Edit: Expected output:
A_to_B B_to_A B_to_C ....
NA 1 NA
NA 2 NA
-3 NA -2
It is litterally a split of each variable (column) based on a condition. Thanks!