mardi 10 février 2015

How to use an if then statement in R to create a new variable based on another

I have a data frame with Column1, which can take the value of any letter of the alphabet. I want to create a second column that spells out the number corresponding to that letter. I am trying to do this with an if then statement... But keep getting an error. Sorry this is a simple question but I have tried the R for dummies website http://ift.tt/1EpmKMX with no luck!


x$Column2 <- NULL if (x$Column1 == "A") then[x$Column2 <- "One"]


Aucun commentaire:

Enregistrer un commentaire