Here is a minimal reproducible example that generates the error:
comb3 <- function(x) {
if (x == "Unable to do") {
x = 0
}
}
Here is my original function:
comb <- function(x) {
if (x == "Unable to do") {
x = 0
} else if (x == "Very difficult to do") {
x = 1
} else if (x == "Somewhat difficult to do") {
x = 2
} else if (x == "Not difficult") {
x = 3
}
}
I am trying to use this function on a column sampled below. I get this error:
Warning messages:
1: In if (x == "Unable to do") { :
the condition has length > 1 and only the first element will be used
2: In if (x == "Very difficult to do") { :
the condition has length > 1 and only the first element will be used
Here is a sample of what the data in one column looks like:
sample <- c("Unable to do", "Somewhat difficult to do", "Very difficult to do", "Unable to do", "Not difficult","Unable to do","Very difficult to do", "Not difficult", "Unable to do", "Not difficult")