dataframe - How to extract the indexes values from a list and replace them in another specific data frame R? -


data frame x contains information especific population, say:

  ef org_pres type_cont  r01  federal      base  ax1  outcome      clue  r02  federal      opt1 

and have 3 lists our vectors works me catalogs dataframes this:

list1

 id_ef  ef     35 r01     36 ax1     37 r02 

list2

 id_type_cont type_cont           101      opt1           201      base           301      clue 

list3

 id_org_pres org_pres         0034  federal         0035  outcome 

what need extract values data frame x , replace them respective indexes values lists. output expect data frame looks one:

 ef org_pres type_cont  35     0034       201  36     0035       301  37     0034       101 

it not have same x data frame.

i not want make loop function data frame x large, , variables factors high number of leves.

op -- in future, please make easy copy-paste sample data, noted in comments above.

one approach problem use combination of reduce , merge:

out <- reduce(function(x, y) {   merge(x, y, all.x = true) }, list(list1, x, list2, list3))[, paste0("id_", names(x))] out #   id_ef id_org_pres id_type_cont # 1    35        0034          201 # 2    37        0034          101 # 3    36        0035          301 

Comments