[R] Odp: storing text and decimal values in a matrix form

Petr PIKAL petr.pikal at precheza.cz
Tue Sep 11 15:56:47 CEST 2007


Hi

Although not specifically stated in help page, matrix is a vector with dim 
attribute. Therefore it can have only one type of values either numeric or 
character or logical or factor. So if you want textual and numeric values 
you probably have to stick with data frames.

Regards
Petr
petr.pikal at precheza.cz

r-help-bounces at r-project.org napsal dne 11.09.2007 15:43:20:

> Hi,
> 
> I would like to store some text and decimal values in the following 
> form:
> 
> name   dec.val   dec.val   ...   dec.val
> name   dec.val   dec.val   ...   dec.val
> ...
> name   dec. val    dec.val   ...   dec.val
> 
> To do so, I created a matrix of the necessary size (x row per y cols) 
> with the command
> 
> matrixname <- matrix(0,x,y)
> 
> and proceeded to fill in the matrix with information drawn from a 
> data frame.
> 
> The problem is that the resulting matrix only has integers at the end 
> of the filling process.
> 
> When I ask:
> class(dataframename[i,j])
> The answer is "factor"
> 
> What is the best way of solving the problem. Should I use a data 
> structure other than a matrix? Or should I make the elements be a 
> different class (other than "factor") when I assign them to the matrix?
> 
> Thanks for any help!
> 
> G.
> 
> 
> 
> 
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list