Skip to content
Prev 125 / 1559 Next

RMySQL and factors

I have just started using the RMySQL package and things are working out
well, but I would like to know if it is possible to return a data.frame
from dbGetQuery with class(dta$race) => factor rather than
class(dta$race) => character. I want to use glm on the resultant data,
but I cant figure out how to change the columns without effort. 

Currently what I do is write the dta to a local file and then re-read it
at which point the columns is of class factor.

Thanks in advance, The code I am using to get the data is:

getrace <- function(connection) {
  sql <- "SELECT race FROM PATIENT"
  rs <- dbGetQuery(connection, sql)

  class(rs$race)  
}

which returns "character" 


Jim