0

I have a dataframe as :-

Country    Disease 1   Disease 2    Disease 3   Disease4 

A           No         No          No          Yes     
B           Yes        Yes         No          No     
C           No         Yes         No          No   
D           No         No          Yes         No  

I want to make as :-

Country     Disease
A           Disease4
B           Disease1
B           Disease2
C           Disease2
D           Disease3

I am unable to do it with:

New_Data_3 <- melt(New_Data2, id = c("Country"))

New_Data_2 is the dataframe.

camille
  • 16,432
  • 18
  • 38
  • 60
Gill
  • 3
  • 3
  • 1
    Welcome to SO; question has nothing to do with `machine-learning` or `rstudio` - kindly do not spam irrelevant tags (removed). – desertnaut Oct 26 '19 at 17:43

1 Answers1

0

You just have to add two more steps to get your desired output after using melt. The code is:

require(dplyr)
require(reshape2)

New_Data_3 = melt(New_Data_2,id=c('Country')) %>% 
  dplyr::filter(value=='Yes') %>% 
  dplyr::rename(Disease = variable) %>% 
  dplyr::select(-value)

Let me know if that works for you.