[R] Data replacement

Lisa lisajca at gmail.com
Tue Jan 5 15:42:11 CET 2010


Dear all,

I have a question and need your help.

I have a dataset that looks like this: 

> data
         id    code1    code2 
1         1        1        4 
2         1        2        3 
3         2        4        4 
4         3        1        5 
5         3        2        4 
6         4        1        1 
7         4        3        4 
8         6        4        3 
9         6        2        2 
10        7        5        2 
11        1        1        4 
12        1        3        2 
13        3        4        4 
14        4        1        4 
15        4        3        2 
16        5        1        1 
17        5        4        3 
18        7        1        4 
19        7        2        3 
20        8        1        1 

I want to change some numbers in the columns of “code1” and “code2” based on
“indx” as below

> indx
[[1]]
        code 
1          1 
2          3 
3          4 
4          6 
5          8 
[[2]]
        code 
1          1 
2          2 
3          4 
4          6 

For example,  for the first ten records (rows) of my dataset, I want to
change 2 to 3, 3 to 4, 4 to 6, and 5 to 8 in both “code1” and “code2”, while
for the last ten records, I want to change 3 to 4 and 4 to 6.

Can anybody please help how to get this done? Thanks a lot in advance

Lisa

-- 
View this message in context: http://n4.nabble.com/Data-replacement-tp999060p999060.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list