I have the following dataset:

```
name    date         cat1    cat2    cat3    cat4    cat5
joe     15/09/2013   A       D       C       D       NA
joe     14/09/2013   D       A       C       NA      NA
joe     13/09/2013   A       C       NA      NA      NA
jack    15/09/2013   G       I       K       D       O
jack    14/09/2013   H       G       O       M       K

```

For each person I want to calculate a percentage of how similar each of their categories are compared with each other. e.g.

```
name    percentage
joe     88.9%      
jack    60%

```

Notice that the NAs are ignored and the number of times a category appears is irrelevent.

To walk you through my logic (which may be wrong, or there may be a better way to do this, if so please say): Let's take joe as an example, 

> 
> 1. row1 (15/09/2013) compared to row2 (14/09/2013) matches 100%
> 2. row1 (15/09/2013) compared to row3 (13/09/2013) matches 66%
> 3. row2 (14/09/2013) compared to row3 (13/09/2013) matches 66%
> 4. row2 (14/09/2013) compared to row1 (15/09/2013) matches 100%
> 5. row3 (13/09/2013) compared to row1 (15/09/2013) matches 100%
> 6. row3 (13/09/2013) compared to row2 (14/09/2013) matches 100%
> 
> 
> 

so the average score is 88.9%

For jack, only categories 'G', 'K', 'O' appear in both rows so the average score is 60% 

I have looked into the ddply function in R, but i'm not sure if I can use it to create the dataframe above (name, percentage). My other options, one which I think I should be avoiding as I'm sure there must be a more efficient way to do it in R, is to created a R script with nested for loop..eek! 

And my final option, which potentially may be the best way (as this dataframe will be quite large) is to use Python, hence if anyone knows how to do this is Python (guessing we will be using Pandas) I would be greatful for some help.

So to be clear, two questions:

1. If it is possible to use ddply can someone please show me how, else does anyone have any other ideas on how I can tackle this in r?
2. Using the small data frame above can someone provide an example of how they would tackle this problem in Python?