r - Join data frames where 'by' is an expression to get column name -


i writing loop join data frames in r , using merge function. here's code have:

for (j in 1:5){   if(j == 1){     iteration <- merge(iteration, paste0("var", j),                         by.x = eval(as.name(paste0("x", j))),                         by.y = "code", all.x = true)   } } 

iteration data frame have in global environment , have data frames titled var1, var2, var3 etc. trying merge iteration dataframe each var data frame in loop. using code have now, error in fix.by(by.y, y) : 'by' must specify uniquely valid column

i understand by.x needs column name specified same way have by.y. however, have variables x1, x2, x3 defined previous functions in global environment correspond column names in datasets var1, var2, use these names by.x part. there way call names x1, x2 defined in global environment by.x in loop? or there alternative merge allow me better?


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -