I made two columns which show pairs of prescribed meds. Some of these pairs repeat, and I need to find the frequency/count of the unique pairs. Can anyone help me?
- its a big data, I am just posting this photo to show my variables.
I made two columns which show pairs of prescribed meds. Some of these pairs repeat, and I need to find the frequency/count of the unique pairs. Can anyone help me?
If your data is df, and your medication columns are med1 and med2, you can do:
library(dplyr)
count(df, med1,med2)
but if it really is a large dataset, you might benefit from using data.table instead:
library(data.table)
setDT(df)[,.N, .(med1,med2)]