Mark Alen
2011-Jun-24 02:58 UTC
[R] Converting an ftable (contingency table) to a dataframe in R
I am generating an ftable (by running ftable on the results of a xtabs command) and I am getting the following. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Var1? Var2 date ? ? ? ? ? ? ? ? group? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 2007-01-01? ? ? ? ? q1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1? ? 9 ? ? ? ? ? ? ? ? ? ? ?q2 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?2? ? 8 ? ? ? ? ? ? ? ? ? ? ?q3 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?3? ? 7 2007-01-02? ? ? ? ? q1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?6? ? 6 ? ? ? ? ? ? ? ? ? ? ?q2 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?7? ? 5 ? ? ? ? ? ? ? ? ? ? ?q3 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?8? ? 4 I understand that it is a ftable class but I'd like to store is as the following. I am wondering if there is any efficient way of doing it in R? date ? ? ? ? ? ? ? ? group? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Var1? Var2? ? ? ? ? 2007-01-01? ? ? ? ? q1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1? ? 9 2007-01-01? ? ? ? ? q2 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?2? ? 8 2007-01-01? ? ? ? ? q3 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?3? ? 7 2007-01-02? ? ? ? ? q1 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?6? ? 6 2007-01-02? ? ? ? ? q2 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?7? ? 5 2007-01-02? ? ? ? ? q3 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?8? ? 4 I don't know how this email will look in the mailing list so I have also asked it here http://stackoverflow.com/questions/6462769/converting-an-ftable-contingency-table-to-a-dataframe-in-r
Richard M. Heiberger
2011-Jun-24 05:05 UTC
[R] Converting an ftable (contingency table) to a dataframe in R
Use as.data.frame() See ?ftable for details. ftable(Titanic, row.vars = 1:3) as.data.frame(.Last.value) Rich On Thu, Jun 23, 2011 at 10:58 PM, Mark Alen <linux_jvm@yahoo.com> wrote:> I am generating an ftable (by running ftable on the results of a xtabs > command) and I am getting the following. > Var1 > Var2 > date group > 2007-01-01 q1 1 9 > q2 2 8 > q3 3 7 > 2007-01-02 q1 6 6 > q2 7 5 > q3 8 4 > > I understand that it is a ftable class but I'd like to store is as the > following. I am wondering if there is any efficient way of doing it in R? > date group Var1 > Var2 > 2007-01-01 q1 1 9 > 2007-01-01 q2 2 8 > 2007-01-01 q3 3 7 > 2007-01-02 q1 6 6 > 2007-01-02 q2 7 5 > 2007-01-02 q3 8 4 > > > > I don't know how this email will look in the mailing list so I have also > asked it here > > http://stackoverflow.com/questions/6462769/converting-an-ftable-contingency-table-to-a-dataframe-in-r > > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]