On May 23, 2010, at 8:41 PM, Claudia Rodriguez wrote:

Dear Friends.
I am just starting to use R. And in this occasion I want to construct a high-dimensional contingency table, because I want to crate a mosaic plot
with the vcd package.
My table is in this format:

   año ac.rep    cat.gru conteos
1  2005      R    parejas     253
2  2005      N    parejas      23
3  2006      R    parejas     347
4  2006      N    parejas      39
5  2007      R    parejas     266
6  2007      N    parejas      83
7  2005      R solitarios      53
8  2005      N solitarios       1
9  2006      R solitarios     109
10 2006      N solitarios       8
11 2007      R solitarios      85
12 2007      N solitarios      34
13 2005      R      trios      29
14 2005      N      trios       1
15 2006      R      trios      62
16 2006      N      trios      19
17 2007      R      trios      48
18 2007      N      trios       3

How can I do this?
I saw the help of the "mosaic" command, and I found that the files are like a hig-dimensional contingency table (for example "Tytanic" data), but I was
unable to do the change.

mosaic's help page says you need to supply a data.frame or a contingency table. Given that you do not have separate records for each individual, but rather have counts in the last column, you can use xtabs to create a table object. Note the help page of xtabs says:

## xtabs() <-> as.data.frame.table()
You need to tell xtabs which column has the counts.

xtabs(conteos ~.,dta)
mosaic( cat.gru ~año, data = xtabs( conteos ~., dta))

--
David.

Thank you very much!!!
With best wishes

--
Claudia I. Rodríguez-Flores
Maestra en Ciencias Biológicas
Laboratorio de Ecología, UBIPRO
UNAM FES-Iztacala
52-55-56231130


David Winsemius, MD
West Hartford, CT

______________________________________________
[email protected] 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.

Reply via email to