[R] mysql retrive question

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon Apr 4 16:46:52 CEST 2005


simone gabbriellini <ogabbrie at tin.it> writes:

> hello R-Users,
> I have this simple but not for me question:
> 
> I do:
> 
>  > res<-dbSendQuery(con, "SELECT * FROM tabellaProva")
>  > myDataFrame<-fetch(res)
>  > myDataMatrix<-as.matrix(myDataFrame[,-1])
>  > namerows(myDataMatrix)<-as.character(myDataFrame[,1])
> 
> and I have:
> 
>        io  tu
> io  "0" "1"
> tu  "1" "0"
> 
> my problem is that the content of the matrix is interpreted by R as
> strings, not as numbers.
> Is there a way to convert those characters to numbers like
> 
>      io  tu
> io  0 1
> tu  1 0

 mode(m)<-"numeric" should do the trick

It looks a bit odd that you seem get numeric data from mySql as mode
"character", but I don't know enough about the interface to say why. 


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list