Replace multible data codes in a datafram with names

Posted by Shabana on Stack Overflow See other posts from Stack Overflow or by Shabana
Published on 2013-06-26T15:53:41Z Indexed on 2013/06/26 16:21 UTC
Read the original article Hit count: 168

Filed under:

I have a problem in replacing codes in a dataframe of 3890 observations. My dataframe has a character variable df$IJN which contains values from 1 to 27. I would like to replace these with meaningful data as follow

If(1 OR 6 OR 10 OR 14 OR 18 OR 22 OR 26) should be replaced with UL. If(3 OR 7 OR 11 OR 15 OR 19 OR 23 OR 27) should be replaced with LL. If(4 OR 8 OR 12 OR 16 OR 20 OR 24) should be replaced with UR. If(5 OR 9 OR 13 OR 17 OR 21 OR 25) should be replaced with LR.

(U,L,R,and L Refer to Upper, Lower, Right, and Left sites in the order)

I thought of a for() with if() could not manage with it Also thought of df[which(df=="27")] ="LL" may work one by one not sure! Any help please. R v3.1 - Windows 7
E-H Shabana, Paris.

© Stack Overflow or respective owner

Related posts about r