Re: [R] Creating a symmetric contingency table from two vectors with different length of levels in R

From: suparna mitra <mitra_at_informatik.uni-tuebingen.de>
Date: Wed, 06 Apr 2011 14:30:32 +0200

Dear Andrija,
 Thank you very much for your quick reply. It looks like working. Thanks again,
Suparna.

On Wed, Apr 6, 2011 at 2:11 PM, andrija djurovic <djandrija_at_gmail.com>wrote:

> Hi:
>
> Here is one solution:
>
> a<-factor(c(1,2,4,5,6))
> b<-factor(c(2,2,4,5,5))
> b1<-factor(b,levels=c(levels(b),levels(a)[levels(a)%in%levels(b)==FALSE]))
> table(a,b1)
>
> but be aware that levels of b is a subset of levels of a.
>
> Andrija
>
> On Wed, Apr 6, 2011 at 10:39 AM, suparna mitra <
> mitra_at_informatik.uni-tuebingen.de> wrote:
>
>> Hello,
>> How can I create a symmetric contingency table from two categorical
>> vectors
>> having different length of levels?
>> For example one vector has 98 levels
>> TotalData1$Taxa.1
>> [1] "Aconoidasida" "Actinobacteria (class)"
>> "Actinopterygii" "Alphaproteobacteria"
>> [5] "Amoebozoa" "Amphibia"
>> "Anthozoa" "Aquificae (class)"
>> and so on .........
>> 98 Levels: Aconoidasida Actinobacteria (class) ....
>>
>> and the other vector has 105 levels
>> TotalData1$Taxa.2
>> [1] Flavobacteria Proteobacteria
>> Bacteroidetes/Chlorobi group Bacteria
>> [5] Epsilonproteobacteria Epsilonproteobacteria
>> Epsilonproteobacteria
>> and so on ..........
>> 105 Levels: Acidobacteria Aconoidasida Actinobacteria (class) ....
>>
>> Now I want to create a symmetric contingency table.
>> Any quick idea will be really helpful.
>> Best regards,
>> Mitra
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help_at_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]]



R-help_at_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 and provide commented, minimal, self-contained, reproducible code. Received on Wed 06 Apr 2011 - 20:22:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Apr 2011 - 20:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive