1

I am trying to create a new row for every patient with multiple conditions. This is the dataset.

names <- c("John", "Eve", "Kane", "Peter", "Lee")
age <- c(23, 41, 33, 62, 17)
condition <- c("Fever", "Cough, Flu", "Headache, Soar Throat", "Cough", "Toothache, Knee Pain, Backache")

df_medical <- data.frame(names, age, disease)

This is my desire output:

names age condition
John  23  Fever
Eve   41  Cough
Eve   41  Flu
Kane  33  Headache
Kane  33  Soar Throat
Peter 62  Cough
Lee   17  Toothache
Lee   17  Knee Pain
Lee   17  Backache

The conditions are a finite list. I have about 30 of them. They are always separated by commas. I have no idea how to do it. Can anyone help?

0 Answers0