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

IOANNA IOANNOU ii54250 at msn.com
Mon Oct 5 18:10:29 CEST 2015


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','N','Y','N','N') )

 

I want to add a column c which will change 'C' to 'D' if column b is 'Y'.

 


> Dat

  a b c

1 A N A

2 A N A

3 C Y D

4 B N B

5 C Y D

6 C N C

7 B N B

	


Any ideas?

 

Best, 

ioanna

 


	[[alternative HTML version deleted]]



More information about the R-help mailing list