I’d like to use an if statement to create a new column from a vector. However, the result only inputs the first value from the vector all the way down the column. Is there a way to get it to put the vector in? I’ve tried c() and as.character(). Any help much appreciated!
data <- data.frame(n = seq(1:21))
ladder1 <- c(50, 75, 100, 125, 150, 200, 250, 300, 350, 400, 450, 475, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000)
ladder2 <- c(50, 75, 100, 200, 250, 300, 350, 400, 450, 475, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000)
data$ladder <- ifelse(nrow(data) == 23, ladder1,
ifelse(nrow(data) == 21, ladder2))
Aucun commentaire:
Enregistrer un commentaire