ClarityParity - 4 months ago 18

R Question

How can I find out the fraction of rows between two columns match in a data frame?

For example, I have the below data frame:

`Col1 Col2`

A B

A A

A C

B C

B A

B B

C B

C C

C A

Here, the proportion of matching rows is ~33%

Answer

Something like,

```
sum(df$Col1 == df$Col2)/nrow(df) * 100
#[1] 33.33333
```

Counting the values of equal valued columns and dividing it by number of rows.