DATA <- data.frame(
LONDON= c(2,0,1,3,0,1),
STOKE = c(45, 40, 6, 22, 16, 10),
DERBY = c(5, 9, 8, 9, 2, 3),
NEWCASTLE = c(7, 6, 4, 10, 12, 8),
MANCHESTER = c(2, 12, 1, 7, 8, 3),
WATFORD = c(9, 2, 4, 6, 13, 6),
KENT = c(1, 3, 23, 7, 12, 2),
SURREY = c(2, 8, 4, 5, 1, 4),
ESSEX = c(4, 12, 7, 9, 5, 1),
HULL = c(1,3, 2, 4, 3, 1))
I wanted to create a "NEW_COL" column, which says "YES" or "NO" based on four different value columns. I want the new column to have a "YES" (otherwise have a ‘NO’) when DERBY or NEWCASTLE or SURREY is > 7 or when KENT or HULL = 2 I also want the "NEW_COL" column to be the second column in my dataset.
I thought something like this (below) would have done it, but it didn't. Any help on what I’m doing wrong here/how to navigate through.
DATA2 <- DATA %>% mutate(NEW_COL = ifelse(rowSums(select(., DERBY:NEWCASTLE) > 7 | select(., SURREY >7) | select(., KENT == 2) | select(., HULL == 2), na.rm = TRUE), 'Yes', 'No'), .before = 2)