Dear all,
I am currently studying categorical data analysis, if I have two tables:
R> cross
      sex cross death count
1  FEMALE   WEF   YES    26
2    MALE   WEF   YES    14
3  FEMALE   OGG   YES    32
4    MALE   OGG   YES    43
5  FEMALE   TGA   YES     8
6    MALE   TGA   YES    10
7  FEMALE   WEF    NO     6
8    MALE   WEF    NO     7
9  FEMALE   OGG    NO    26
10   MALE   OGG    NO    12
11 FEMALE   TGA    NO    16
12   MALE   TGA    NO    26
R> age
     sex age death count
1 FEMALE 17Y   YES    16
2   MALE 17Y   YES     4
3 FEMALE 18Y   YES    40
4   MALE 18Y   YES    51
5 FEMALE 17Y    NO    32
6   MALE 17Y    NO    42
7 FEMALE 18Y    NO    26
8   MALE 18Y    NO    15
- How to merge two tables.
- How to expand both tables such as:
sex age cross death
FEMALE 17Y WEF YES
...
FEMALE 18Y TGA NO
Warm regards,
Xiyan Lon
This email has been sent from a virus-free computer protected by Avast.
www.avast.com <https://www.avast.com/sig-email>
<#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
	[[alternative HTML version deleted]]
I can see no coherent way to merge these two tables. They do not appear to have consistent definitions for uniqueness of individual rows. Nor do they have consistent column definitions. If you think they do, you will need to be more clear in your question about how you want them to be merged. As for expanding, you might try using something like ageExpand <- age[ rep( seq_along( age[[1]] ), times=age[,"count"] ), 1:3 ] On Tue, 23 Feb 2016, Xiyan Lon wrote:> Dear all, > I am currently studying categorical data analysis, if I have two tables: > > R> cross > sex cross death count > 1 FEMALE WEF YES 26 > 2 MALE WEF YES 14 > 3 FEMALE OGG YES 32 > 4 MALE OGG YES 43 > 5 FEMALE TGA YES 8 > 6 MALE TGA YES 10 > 7 FEMALE WEF NO 6 > 8 MALE WEF NO 7 > 9 FEMALE OGG NO 26 > 10 MALE OGG NO 12 > 11 FEMALE TGA NO 16 > 12 MALE TGA NO 26 > > R> age > sex age death count > 1 FEMALE 17Y YES 16 > 2 MALE 17Y YES 4 > 3 FEMALE 18Y YES 40 > 4 MALE 18Y YES 51 > 5 FEMALE 17Y NO 32 > 6 MALE 17Y NO 42 > 7 FEMALE 18Y NO 26 > 8 MALE 18Y NO 15 > > - How to merge two tables. > - How to expand both tables such as: > > sex age cross death > FEMALE 17Y WEF YES > ... > FEMALE 18Y TGA NO > > > Warm regards, > Xiyan Lon > > This email has been sent from a virus-free computer protected by Avast. > www.avast.com <https://www.avast.com/sig-email> > <#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >--------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
Hi Xiyan, It looks like your tables have different numbers of cases. There are: 66 DEAD FEMALES in "cross" 56 DEAD FEMALES in "age" 48 NON-DEAD FEMALES in "cross" 58 NON-DEAD FEMALES in "age" and so on. Perhaps there is some mistake with the counts. If this is the problem you could expand the counts to individual lines in a merged data frame using the sex and death information. Jim On Tue, Feb 23, 2016 at 5:46 AM, Xiyan Lon <xiyanlon at gmail.com> wrote:> Dear all, > I am currently studying categorical data analysis, if I have two tables: > > R> cross > sex cross death count > 1 FEMALE WEF YES 26 > 2 MALE WEF YES 14 > 3 FEMALE OGG YES 32 > 4 MALE OGG YES 43 > 5 FEMALE TGA YES 8 > 6 MALE TGA YES 10 > 7 FEMALE WEF NO 6 > 8 MALE WEF NO 7 > 9 FEMALE OGG NO 26 > 10 MALE OGG NO 12 > 11 FEMALE TGA NO 16 > 12 MALE TGA NO 26 > > R> age > sex age death count > 1 FEMALE 17Y YES 16 > 2 MALE 17Y YES 4 > 3 FEMALE 18Y YES 40 > 4 MALE 18Y YES 51 > 5 FEMALE 17Y NO 32 > 6 MALE 17Y NO 42 > 7 FEMALE 18Y NO 26 > 8 MALE 18Y NO 15 > > - How to merge two tables. > - How to expand both tables such as: > > sex age cross death > FEMALE 17Y WEF YES > ... > FEMALE 18Y TGA NO > > > Warm regards, > Xiyan Lon > > This email has been sent from a virus-free computer protected by Avast. > www.avast.com <https://www.avast.com/sig-email> > <#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >[[alternative HTML version deleted]]
Hi Xiyan, You don't show your original data, so * If you produced `cross` and `age` tables by summing the counts from a single larger data set, go back to that and do it again. but now include age/ * Otherwise, you can use vcdeExtra::expand.dft()` on both of these data sets to expand to individual observations, and merge those. In general, you'll get better replies by including a reproducible example, rather than summary output from the console. -Michael On 2/22/2016 1:46 PM, Xiyan Lon wrote:> Dear all, > I am currently studying categorical data analysis, if I have two tables: > > R> cross > sex cross death count > 1 FEMALE WEF YES 26 > 2 MALE WEF YES 14 > 3 FEMALE OGG YES 32 > 4 MALE OGG YES 43 > 5 FEMALE TGA YES 8 > 6 MALE TGA YES 10 > 7 FEMALE WEF NO 6 > 8 MALE WEF NO 7 > 9 FEMALE OGG NO 26 > 10 MALE OGG NO 12 > 11 FEMALE TGA NO 16 > 12 MALE TGA NO 26 > > R> age > sex age death count > 1 FEMALE 17Y YES 16 > 2 MALE 17Y YES 4 > 3 FEMALE 18Y YES 40 > 4 MALE 18Y YES 51 > 5 FEMALE 17Y NO 32 > 6 MALE 17Y NO 42 > 7 FEMALE 18Y NO 26 > 8 MALE 18Y NO 15 > > - How to merge two tables. > - How to expand both tables such as: > > sex age cross death > FEMALE 17Y WEF YES > ... > FEMALE 18Y TGA NO > > > Warm regards, > Xiyan Lon > > This email has been sent from a virus-free computer protected by Avast. > www.avast.com <https://www.avast.com/sig-email> > <#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > > [[alternative HTML version deleted]] >