[R] How to merge two tables

Michael Friendly friendly at yorku.ca
Tue Feb 23 14:50:04 CET 2016


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]]
>



More information about the R-help mailing list