[R] reshaping data?

Thomas Lumley tlumley at u.washington.edu
Thu Sep 29 16:05:16 CEST 2005


On Thu, 29 Sep 2005, Karin Lagesen wrote:

>
> 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.
>

If your variables are called, say, id and value, and value is between 0 
and 1 then

table(id,cut(value,breaks=(0:10)/10))

works.

 	-thomas




More information about the R-help mailing list