Skip to content
Back to formatted view

Raw Message

Message-ID: <x2ekdq7g6b.fsf@turmalin.kubism.ku.dk>
Date: 2005-04-04T14:46:52Z
From: Peter Dalgaard
Subject: mysql retrive question
In-Reply-To: <737ba45250b42aa1d804b75bd4871750@tin.it>

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