merge - R Mysql help-need to do a calculation from variables in different tables -


i'm (very!) new r , mysql , have been struggling , researching problem days. appreciate help.

i need complete mathematical expression 2 variables in 2 different tables. essentially, i'm trying figure out how old subject (dob in 1 table) when serviced (date of service in table). have identifying variable same in both.

i have tried merging these:

age<-merge("tbl1", "tbl2", by=c("patient_id") all= true) 

this returns:

error in fix.by(by.x, x) : 'by' must specify uniquely valid column 

i have tried sub-setting keep variables of interest, is not working because believe sub-setting works numbers not characters..right?

again, appreciate help. in advance

since new data.base , think should use dplyr here. abstraction layer many data base providers. not have deal db problems. here show simple example of where:

  1. i read tables mysql
  2. merge table assuming having unique shared variable

the code:

library(dplyr) library(rmysql) ## create connection sdb <- src_mysql(host = "localhost", user = "foo", dbname = "bar", password = getpassword()) # reading tables tbl1 <- tbl(sdb, "table1_name") tbl2 <- tbl(sdb, "table2_name") ## merge : step can done using dplyr  age <- merge(tbl1, tbl2, all= true)   

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -