[R] table: output: all variables in rows

David Winsemius dwinsemius at comcast.net
Mon Apr 2 16:53:34 CEST 2012


On Apr 2, 2012, at 7:11 AM, Marion Wenty wrote:

> Dear people,
>
> I would like to create a table out of a data.frame.
>
> How can I determine, which variables are put in the rows and which  
> in the
> columns?
> I would like to get all the variables in the ROWS:
>
> I am including a simple example:
>
> D<-data.frame(age=c(8,9,10),county=c("B","W","W"))
>
> the output should have the following structure:
>
> 8  B  1
>
> 8  W  0
>
> 9  B  0
>
> 9  W  1
>
> 10 B  0
>
> 10 W  1

You can use the order() function with "[" to rearrange this to suit  
you needs:

 > as.data.frame(xtabs(~age+county, data=D))
   age county Freq
1   8      B    1
2   9      B    0
3  10      B    0
4   8      W    0
5   9      W    1
6  10      W    1
>
>
> 	[[alternative HTML version deleted]]

Posting in HTML is considered impolite on Rhelp.

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list