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
Thank you very much for your help in advance!
Marion
[[alternative HTML version deleted]]
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 1You 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
Seemingly Similar Threads
- maptools: using to sets of information (within two shape files) for one plot
- binding all elements of list (character vectors) to a matrix as rows
- function: as.integer
- open source editor for r for beginners
- writing data from several matrices in R into one excel-file with several sheets