Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R- sqldf -need explicit units for numeric conversion

Tags:

r

sqldf

I need to join 2 tables using a Date field

> class(pagos$pseudo_1mes)
[1] "Date"
>  class(pseudo_meses$pseudo_1mes)
[1] "Date"

My code is:

library(sqldf)

pagos<-sqldf("select a.*, b.mes_atras from pagos a 
        left join pseudo_meses b
      on a.pseudo_1mes=b.pseudo_1mes")

And I get the following error and no result:

Error in asfn(rs[[i]]) : need explicit units for numeric conversion

How can I solve it? Thanks

like image 996
GabyLP Avatar asked Sep 24 '14 20:09

GabyLP


2 Answers

One of my variables had class = 'difftime' instead of regular numeric because I subtracted dates. SQLDF does not work with the difftime class. What happened for me was that I had a data.table, subtracted some dates, and ended up with a difftime variable type. I converted to it to data.frame and when I did the subtraction again it was numeric.

like image 52
winampman Avatar answered Sep 21 '22 14:09

winampman


I got the same problem. My solution is to add (method = "name__class") to the end of the command, such as:

sqldf("select * from pagos", method = "name__class")

However, it seem the format of date variable will be changed, albeit the date variable can be updated later. I think this is still a useful solution, since my purpose is to get sqldf work to solve a complex task while update a column is relatively much easier.

like image 26
Young Avatar answered Sep 24 '22 14:09

Young