I have a dataframe as below. I want to combine rows based on duplicates in column person. However, is it possible for specified columns (Beer, Cola, Wodka in this case) that a certain value (1 in this case) overrules other values (0 in this case).
Current dataframe:
person <- c("John", "John", "Alex", "Nicole", "Nicole")
Sex <- c("M","M","W", "W", "W")
Beer <- c(1,1,1,1,0)
Cola <- c(0,1,0,0,0)
Wodka <- c(0,1,0,0,1)
df <- data.frame(person,Sex,Beer,Cola,Wodka)
Outcome should be:
person <- c("John", "Alex", "Nicole")
Sex <- c("M", "W", "W")
Beer <- c(1,1,1)
Cola <- c(1,0,0)
Wodka <- c(1,0,1)
df <- data.frame(person,Sex,Beer,Cola,Wodka)
Thanks.