Skip to content
Prev 68802 / 398506 Next

How to change variables in datasets automatically

Try:

a <- data.frame(Sepal.Length=1:4, Sepal.Width=2:5,
                Petal.Length=3:6, Petal.Width=4:7, 
                Species=rep("rosa",4))
b <- iris[1:10,]
newtest.iris <- rbind(a,b)
names(newtest.iris) <- c("SL", "SW", "PL", "PW", "Class")
newtest.iris$Class <- as.numeric(newtest.iris$Class) - 1

HTH,
Andy