Merge a dataframe with an rda file in r

140 views Asked by At

I'm building a process where I need to import 4 large txt data sets on a recurring basis, the files include multiple variables with codes values that need to be converted into a tangible values, I.e. title_code 01 = Manager. I've created 12 rda files to support conversion, the codes are constant but I need to refresh the import files periodically.

I have not seen any examples of dplyr or sqldf that uses rda files for this purpose, seemed like a good way to store the data like temp tables, is there a better approach?

Input Data

 id <- c(1,2,3,4)
    name <- c("John","Bill","Mary","Cindy")
    title_code <- c(1,2,3,4)
    df1 <- data.frame(id,name,title_code)   
    
    title_code <- c(1,2,3,4)
    title <- c("Manager", "Officer", "Sales", "VP")
    df2 <- data.frame(title_code,title) 

Can I substitute an rda file for df2

library(sqldf)
df3 = sqldf('select df1.id, df1.name, df2.title 
      from df1 left join df2 
            on df1.title_code = df2.title_code')
df3

Expected Outcome

enter image description here

0

There are 0 answers