Create unique ID from the existing two columns with condition in r -


my data table has 2 variable old_id , new_id.

1)the below code creates new_id1 column, if na present in new_id column takes old_id.

2)if new_id not na same value stay back

3)but if both old id , new id same should create random number should unique in new_id1 column.

code:

    dt[is.na(new_id),new_id1:=old_id]      old_id  new_id new_id1     1         na     1     2         2      13     3         4      11     4         na     12     5         9      9     6         10     10     7         8      8     3         na     3 

please me achieve 3rd point through code.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -