I have a simplified dataframe:
test <- data.frame(
x = c(1,2,3,NA,NA,NA),
y = c(NA, NA, NA, 3, 2, NA),
a = c(NA, NA, NA, NA, NA, TRUE)
)
I want to create a new column rating
that has the value of the number in either column x
or column y
. The dataset is such a way that whenever there's a numeric value in x
, there's a NA
in y
. If both columns are NA
s, then the value in rating
should be NA
.
In this case, the expected output is: 1,2,3,3,2,NA