I have some code:

```
test<-therapyDF %>% group_by(therapyDF$prodcode) %>% summarize(count=n_distinct(therapyDF$patid))

```

that is designed to group all prodcode entries (drug) and then count how many patients (patid) have an instance of each drug. For example, the raw data is held in a dataframe similar to:

```
patid  prodcode
1       A
1       B
2       C
3       A
3       A
3       B

```

Thus, output will be:

```
A 2
B 2
C 1

```

Is there any way of parallelising this code? The real data is in excess of 100 million records and it's been more than 8 hours of running in serial. 
I'm struggling to adopt the \*apply methodologies of R and the numerous R parallel packages. Splitting the original data frame would be a bit tricky, as the data is not very well organised (just how I got it) and it would require grouping an extracting by the $patid. I am running this on an 8 core intel Linux box.

Thanks