I have a data frame like the one below
AccountNo<-c(11223344,11223344,11223344,1133399,1133399,127788,127788)
transactiondesc<-c("BUY","BUY","SELL","SELL","SELL","BUY","BUY")
I want to the code to see for an account if it has both BUY and SELL (regardless of the number of BUY and SELL)
expected output:
AccountNo<-c(11223344,11223344,11223344,1133399,1133399,127788,127788)
transactiondesc<-c("BUY","BUY","SELL","SELL","SELL","BUY","BUY")
TRUE/FALSE<-c("TRUE","TRUE","TRUE","FALSE","FALSE","FALSE","FALSE")
I was using the following approach:
Testing<-Combined %>%
group_by(AccountNo)%>%
mutate(BUY = case_when(transactiondesc == 'BUY' ~ 1,
TRUE ~ 0))%>%
mutate(BUY = case_when(transactiondesc == 'SELL' ~ 1,
TRUE ~ 0))
Didn't get what i want