[R] sqlQuery of variable of type varchar - confusion with "."

Duncan Murdoch murdoch at stats.uwo.ca
Thu Nov 29 13:30:08 CET 2007


On 11/29/2007 7:03 AM, Søren Højsgaard wrote:
> Dear list,
> I have a rather large dataset in SAS which I export to a SQLite database for subsequent use in R.
>  
> One of the columns is
> cowidp	
> 1881501224.2	
> 1881501224.2	
>  
> and the column is stored as a character in SAS. It becomes a varchar in the database (it should be - it is an identifier; not a number). Reading this into R gives
>       cowidp
> 1 1881501224
> 2 1881501224
> ....
> - i.e. the ".2" is stripped off - and it becomes a numeric variable
>  
> However, if I store replace "." with "_" in my SAS data then the column in my database is
>  
> cowidp	
> 1881501224_2	
> 1881501224_2	
>  
> Reading into R gives
>         cowidp
> 1 1881501224_2
> 2 1881501224_2
> 
> as it "should be" - it becomes a factor
>  
> Is the fact that the "."-part does not seem to work a bug in sqlQuery (or somewhere else) or is it the intention that things containing a "." are converted into numeric values if possible?

If you're using sqlQuery from RODBC, then the as.is argument of 
sqlGetResults is relevant.  It defaults to FALSE, and tries to convert 
things based on how they look.

Duncan Murdoch



More information about the R-help mailing list