1

I have the attached dataframe (here) and I need to reshape it to be in the format shown below enter image description here

Basically, I want to add each compare each traet group (LA, RA, BiA) to NP treat group and create a column that is concatenate between Studlab and treat arm.

I tried to figure this out using my prior answered question (here) but I could not. Any advice will be greatly appreciated.

enter image description here

Mohamed Rahouma
  • 1,084
  • 9
  • 20

1 Answers1

0

It's hard to help you without a data sample and without knowing exactly where 2Total and Group2.event is comming from. But the basis should be somthing like:

df %>% 
 gather(treat2:treat4, key = "key", value = "tmp_compare_groupe") %>% 
 mutate(Compare_Groups = paste0("NP_", tmp_compare_groupe), 
        2nd.Total = case_when(tmp_compare_groupe == "LA" ~ LA,
                              tmp_compare_groupe == "RA" ~ RA,
                              tmp_compare_groupe == "BIA" ~ BIA,
                               ))

I don't know where Group2.event is comming from. After you have calculated all columns you have to select the columns you need.

domaeg
  • 431
  • 2
  • 6