How to generate a list

Hi

Below is my code for getting a list of diagnosis for each patient. The result is the patient's number and the list of diagnosis. I want only the list of diagnosis without the patient number separated by a comma. like this for example,

I10,G47,E78

I10,E78

G47

I10,R06

I10,R06,E78

Any ideas? please explain. Thank you!

trans_list<-list()

for (row in 1:nrow(diag_colist)){

patient_sk<- paste("pk",diag_colist$patient_sk[row], sep="")

diag<-diag_colist$morbid_1[row]

if (patient_sk %in% names(trans_list)){

pat_list <-trans_list[[patient_sk]]

if (!diag %in% pat_list){

pat_list<-c(pat_list, diag)

trans_list[[patient_sk]]<-pat_list

}

}

else {

trans_list[[patient_sk]]<-diag

}

}

submitted by /u/malshak1
[link] [comments]

from Tere tulemast | Languagelearning https://ift.tt/2vxRNNb
via Learn Online English Speaking

Comments