-1

I have 2 text files (tab delimited). The 1st file is the main file and the 2nd one is made from the 1st file. The main file looks like this:

Rownames    IDs      SAM5511   SAM5566
1           EGS001    2        23 
.     
.
550         ESF012    3        76
.
.
1001        EFP125    4        55 

And the 2nd one looks like this:

X     log    p-val
1     4.5    0.001
550   2.3    0.021
1001  1.6    0.0005

I filtered the 1st file and changed the values to get the 2nd file so the number of rows in the 2nd file is less than the 1st one. As you see in the 1st file the 1st column is IDs but that of 2nd file is is the row names of 1st file (since it is filtered, all the rows are not included in the 2nd file). I want to make a text file like the 2nd file but it also has the corresponding IDs from the 1st file and it would be like this:

 IDs      X      log     p-val
 EGS001   1      4.5     0.001 
 ESF012   550    2.3     0.021
 EFP125   1001   1.6     0.0005
akbar
  • 9
  • You posted the same question some hours back. I suggested to use `merge`, `match` etc. In case you don't have the `Rownames` column for `df1`, create one and then `merge` – akrun Jan 05 '15 at 16:34

1 Answers1

0

assuming your files are all in data.frames t1, t2, t3 (the new one).

t3$IDs <- t1$IDs[match(t2$X, rownames(t1))]

this code matches the colum X of t2 to the rownames of t1

c0bra
  • 1,031
  • 5
  • 22