[R] reshaping data?
Jim Lemon
bitwrit at ozemail.com.au
Fri Sep 30 10:58:16 CEST 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
> ..
>
If you have a file named KL.dat with the above data in it:
KL.df<-read.table("KL.dat",header=FALSE)
KL.mat<-as.matrix(table(KL.df))
Jim
More information about the R-help
mailing list