I am writing a simple ifelse statement following another , where I'm trying to classify the index into three groups ( >= 0.8, 0.8 to -0.8, <= -0.8)
I keep getting an error:
In if (df$index >= 0.8) { : the condition has length > 1 and only the first element will be used
index <- c(0.8,0.2,-0.2,0,-1,-1)
df <- data.frame(index)
df$indexclass <- NA
df$indexclass <- if (df$index >= 0.8) {
df$indexclass <- "P"
} else if (df$index <= (-0.8)) {
df$indexclass <- "A"
} else { df$indexclass <- "S"}