I would like to merge two data set using for loop for varilist in r but not happen in assign(paste0("meg_",i),merge(paste0("bc_",i,sep=""),paste0("mr_",i,sep=""), by="caseid"))
Plese suggest me
bc <- read_dta("bc_r2.dta")
mr<- read_dta("master_r1.dta")
r<-c("c6_gen_minc", "c_num_hh")
for(i in seq_along(r)){
assign(paste0("bc_",i),select(bc,r[[i]],caseid))
assign(paste0("mr_",i),select(mr,r[[i]],caseid))
assign(paste0("meg_",i),merge(paste0("bc_",i,sep=""),paste0("mr_",i,sep=""), by="caseid"))
}
In dataset bc and mr, I would like to merge only specific variables (not the whole dataset) so I save the specific variable in r and then merge them in the loop. It is the sample as it has a lot of specific variables to be merged. Merging is not the issue, but how to merge specific variables ( multiple same work). So I try to merge these specific pairs of variables into for loop.
It'd be much nicer without all the renaming & if the output were 'tidy' which could be done a bit like this (not checked this, so please excuse any stupid errors):