Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping leading zeros using RODBC

Tags:

r

leading-zero

I am trying to import data from an Access database into R. I would like to import the CIP codes for some majors, which can contain leading zeros. RODBC is converting the CIP code to a numeric value even though it is defined as text in Access. Can anyone shed light on how I can coerce this field into a text field on import?

like image 255
dmonder Avatar asked Jul 12 '12 13:07

dmonder


2 Answers

Try using the argument as.is = TRUE in the sqlQuery function. That usually does the trick for me.

like image 155
BenBarnes Avatar answered Sep 28 '22 02:09

BenBarnes


library(RODBC)
channel=odbcConnectAccess2007("plz.accdb")
plz = sqlQuery(channel,"SELECT * from PLZ",as.is=TRUE)
like image 39
Dieter Menne Avatar answered Sep 28 '22 04:09

Dieter Menne