Re: [R] Change values of a column based on the values of a third

2015-10-05 Thread Jeff Newmiller
Either Dat$c <- ifelse( "Y"==Dat$b, rep( "D", nrow(Dat) ), Dat$a ) Or (more efficiently) Dat$c <- Dat$a Dat$c[ "Y"==Dat$b ] <- "D" Also, beware of creating data frames without using the stringsAsFactors=FALSE option if you plan to replace levels like this. -

Re: [R] Change values of a column based on the values of a third

2015-10-05 Thread Sarah Goslee
?ifelse I changed Dat to a. have character type instead of factor, and b. actually match what you show in your example instead of already having D. Dat <- data.frame(a= c('A','A','C','B','C','C','B'), b= c('N','N','Y','N','Y','N','N'), stringsAsFactors=FALSE ) Dat$c <- with(Dat, ifelse(b == "Y"

[R] Change values of a column based on the values of a third

2015-10-05 Thread IOANNA IOANNOU
Hello all, I have a rather easy question. I want to add a column to the database which will change the values of vector a based on the values to vector b. Any ideas how? For example: Dat <- data.frame(a= c('A','A','C','B','D','D','B'), b= c('N','N','Y