[R] How to build a matrix of number of appearance?

David Winsemius dwinsemius at comcast.net
Mon Jul 4 16:50:40 CEST 2011


On Jul 4, 2011, at 5:48 AM, UriB wrote:

> I have a matrix of claims at year1 that I get simply by
>
> claims<-read.csv(file="Claims.csv")
> qq1<-claims[claims$Year=="Y1",]
>
> I have MemberID and ProviderID for every claim in qq1 both are  
> integers
>
> An example for the type of questions that I want to answer is
> how many times ProviderID number 345 appears together with MemberID  
> 23 in
> the table qq1
>
> In order to answer these questions for every possible ProviderId and  
> every
> possible MemberID
> I would like to have a matrix that has first column as memberID when  
> every
> memberID in qq1 appears only once and columns that have number of  
> appearance
> of ProviderID==i for every i that has
> sum(qq1$ProviderID==i)>0
>
> My question is if there is a simple way to do it in R

A really quick way of finding this would be:

as.data.frame ( xtabs(  ~ ProviderID +MemberID, data= qq1) )

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list