[R] reshaping data?

Karin Lagesen karin.lagesen at medisin.uio.no
Thu Sep 29 15:16:02 CEST 2005


I have a file like this:


a       0.1
a       0.2
a       0.9
b       0.5
b       0.9
b       0.7
c       0.6
c       0.99
c       0.88

Which I would like to get to be the following matrix:

      0.1     0.2    0.3    0.4  ...  
a     1        2     0       0 
b     0        0     0       0 
..

I.e: each place in the matrix denotes how many entries in each
category that are betwee 0.0 and 0.1, 0.1 and 0.2 and so on.

The way I was thinking of doing it was by constructing an empty matrix
and then doing a for loop testing each element and incrementing in the
matrix as appropriate. However, it struck me that this has to be
easier to do than that. Am I right?

Karin
-- 
Karin Lagesen, PhD student
karin.lagesen at medisin.uio.no
http://www.cmbn.no/rognes/




More information about the R-help mailing list