0

I have a large xlsx file; I am interested in 2 columns: pat_id and param_1.

The original file looks like this (I replaced values with dots just to type faster):

     ......pat_id...........param_1..........
row1 ........123...............0.............
...
...
rowi ........456...............1.............     
...
rowk ........789...............5.............
...
rown ........................................

I have a smaller file:

pat_id | param_1
123        55
456        33
789        22

I want to replace values of param1 in the original file with the values from a smaller file. Like this:

     ......pat_id...........param_1..........
row1 ........123...............55.............
...
...
rowi ........456...............33.............     
...
rowk ........789...............22.............
...
rown ........................................

So far: 1) I read two files into dataframes. 2) I then try to find the row where pat_id == 123, and access the column 'param1' and assign a new value (55).

However, I run into numerous errors.

My last version:

data[data == 123, 'param1'] <- small_data[1, 'param1']

gives an error:

 Error in `[<-.data.frame`(`*tmp*`, data == curr_pat_id, column, value = "55") : 
  non-existent rows not allowed 

For some reason, when data[data == 123, 'param1'] return NA...

I tried to explore join/merge alternatives, didn't find a suitable solution.

Basically I just want to say "where in data pat_id == 123, replace its param_1 value with 55".

Uylenburgh
  • 1,277
  • 4
  • 20
  • 46

0 Answers0