Dear All, I want to create a table for several variables. As example. I have a dataframe with following data: Gender transport driving 1 0 1 0 1 0 1 0 1 Now I want to create a table in the following form: Gender 1 0 Transport 1 2 0 0 0 1 Driving 1 2 0 0 0 1 In which the different percentages are being calculated (row/column). I have tried using ftable() but did not give the desired result (There are a lot of variables and the format makes it impossible to interpret). Is there anyone who can help me with this problem? Thanks in advance. Kind regards, John [[alternative HTML version deleted]]
On Jul 3, 2009, at 1:10 PM, John Lipkins wrote:> Dear All, > > I want to create a table for several variables. As example. I have a > dataframe with following data: > > Gender transport driving > 1 0 1 > 0 1 0 > 1 0 1 > > Now I want to create a table in the following form:gtd <- read.table(textConnection("Gender transport driving 1 0 1 0 1 0 1 0 1 "), header=TRUE)> > Gender > 1 0 > Transport 1 2 0 > 0 0 1 > Driving 1 2 0 > 0 0 1That's really two tables stacked on top of each other. The sum of its entries is 2n. with(gtd, rbind( xtabs( ~ transport + Gender) , xtabs( ~ driving + Gender) ) ) 0 1 0 0 2 1 1 0 0 1 0 1 0 2> > In which the different percentages are being calculated (row/column).Percentages? Don't see any in the requested output. Maybe you really want CroosTables in the gmodels package.> I have > tried using ftable() but did not give the desired result (There are > a lot of > variables and the format makes it impossible to interpret).You could think about using summary or one of its substitutes inside an apply construction. David Winsemius, MD Heritage Laboratories West Hartford, CT
On Jul 3, 2009, at 12:10 PM, John Lipkins wrote:> Dear All, > > I want to create a table for several variables. As example. I have a > dataframe with following data: > > Gender transport driving > 1 0 1 > 0 1 0 > 1 0 1 > > Now I want to create a table in the following form: > > Gender > 1 0 > Transport 1 2 0 > 0 0 1 > Driving 1 2 0 > 0 0 1 > > In which the different percentages are being calculated (row/ > column). I have > tried using ftable() but did not give the desired result (There are > a lot of > variables and the format makes it impossible to interpret). > > Is there anyone who can help me with this problem? > > Thanks in advance. > Kind regards, > > JohnJohn, Take a look at the 'catspec' package by John Hendrickx on CRAN. There is a function in there called 'ctab', which if memory is correct, will do what you want. John had originally posted his code here: https://stat.ethz.ch/pipermail/r-help/2003-February/030400.html and it has been updated to some extent in the package since then. HTH, Marc Schwartz