Gonçalo Ferraz
2007-Sep-11 13:43 UTC
[R] storing text and decimal values in a matrix form
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]]
Petr PIKAL
2007-Sep-11 13:56 UTC
[R] Odp: storing text and decimal values in a matrix form
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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.