[R] How to change dataframe to tables
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Fri Feb 18 10:28:45 CET 2011
say, 'Dat' is your data frame, then one way to do it is:
with(Dat, tapply(freq, list(hair, eye, sex), c))
I hope it helps.
Best,
Dimitris
On 2/18/2011 8:50 AM, Lao Meng wrote:
> The data is in the attachment.
>
> What I wanna get is:
> , , Sex = Male
> Eye
> Hair Brown Blue Hazel Green
> Black 32 11 10 3
> Brown 53 50 25 15
> Red 10 10 7 7
> Blond 3 30 5 8
> , , Sex = Female
> Eye
> Hair Brown Blue Hazel Green
> Black 36 9 5 2
> Brown 66 34 29 14
> Red 16 7 7 7
> Blond 4 64 5 8
>
>
> Then,how to change the dataframe to tables?
>
> Many thanks for your help.
>
> Best
>
>
>
> ______________________________________________
> 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.
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
More information about the R-help
mailing list