Hello all,
I am trying to work on this. I appreciate any help.
We have 3 persons (X,Y,Z)
We have 6 days ('NA','Mon','Tue','Wed','Thr','Fri')
For every person, We are trying to fill a column with either 'C' or 'H'. This column is called Expected_H_OR_C
If a person has one H, he/she will also have NA in the column 'Day'. The expected result for this case is that all his/her other days 'Mon' through 'Fri' will be filled with 'H'.
For all other cases, R should look how many 'C's it has and fill the rest with 'H'
Ex: If person 'Y' has 'C' for days 'Tue' and 'Fri', then the rest of his/her days
'Mon', 'Wed' and 'Thr' will fill with 'H'. If person 'W' has 'C' for his/her days, then
there is nothing to be filled.
days <- rep(c(NA, 'Mon','Tue','Wed','Thr','Fri'), 3)
person <- c(rep('X',6), rep('Y',6), rep('Z',6))
H_OR_C <- c('H',rep(NA,5),NA, 'C',rep(NA,4), NA, rep('C',2),rep(NA,3))
Expected_H_OR_C <- c('H',rep('H',5), 'H','C', rep('H',4), 'H', rep('C',2), rep('H',3))
mydata <- data.frame(days, person, HorC,Expected_H_OR_C)
View(mydata)