Print

Print


Dear All-

I have a data with genotype and medication exposure on repeated dates. I’m trying to table the counts of the genotypes for unique individuals in each medication group . I tried  several codes to summarize the data by genotypes and medications, but with no luck

I used summarize and group_by from dplyr

output<-d1 %>%
group_by(d1$`Med Order Display Name`,d1$`CYP2C19 Genotype`) %>% distinct(d1$`Record ID`)%>%summarise(n())

Another code I tried

with(d1, tapply(d1$`Med Order Display Name`, d1$`CYP2C19 Genotype`, FUN = function(x) length(unique(x))))

I appreciate your input on a direction I should take.



My example data is

Record ID

CYP2C19 Genotype

Med Order Display Name

3

*1/*1

pantoprazole (PROTONIX) injection 40 mg

3

*1/*1

pantoprazole (PROTONIX) injection 40 mg

3

*1/*1

pantoprazole (PROTONIX) EC tablet 40 mg

13

*1/*17

pantoprazole (PROTONIX) 40 MG Tablet Delayed Release

13

*1/*17

pantoprazole (PROTONIX) 40 MG Tablet Delayed Release

13

*1/*17

pantoprazole (PROTONIX) 40 MG tablet

13

*1/*17

pantoprazole (PROTONIX) 40 MG tablet

28

*1/*1

esomeprazole (NexIUM) capsule 20 mg

28

*1/*1

pantoprazole (PROTONIX) EC tablet 40 mg

28

*1/*1

pantoprazole (PROTONIX) 40 MG tablet

28

*1/*1

esomeprazole (NexIUM) capsule 40 mg

52

*1/*1

NEXIUM 40 MG Capsule Delayed Release

52

*1/*1

NEXIUM 40 MG Capsule Delayed Release

52

*1/*1

esomeprazole (NexIUM) 40 MG Capsule Delayed Release

52

*1/*1

NEXIUM 40 MG PO Capsule Delayed Release


I hope I can get an output like that


pantoprazole (PROTONIX) injection 40 mg

pantoprazole (PROTONIX) EC tablet 40 mg

pantoprazole (PROTONIX) 40 MG Tablet Delayed Release

pantoprazole (PROTONIX) 40 MG tablet

esomeprazole (NexIUM) capsule 20 mg

NEXIUM 40 MG Capsule Delayed Release

NEXIUM 40 MG PO Capsule Delayed Release

esomeprazole (NexIUM) 40 MG Capsule Delayed Release


*1/*2

xx

xx

xx

xx

*1/*17

xx

xx

xx

xx

*1/*2

xx

xx

xx

xx

inconclusive

xx

xx

xx

xx

*2/*2

xx

xx

xx

xx

*17/*17

xx

xx

xx

xx




This list strives to be beginner friendly.  However, we still ask that you
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.