df <- data.frame( plant1= c('1','0','1','0','0','1','0','0','1'),
plant2= c('0','1','0','1','1','0','1','1','0'),
Public.1= c('1','0','1','0','0','0','0','0','1'),
Private.1= c('0','0','0','0','0','1','0','0','0'),
Public.2= c('0','0','0','1','1','0','0','1','0'),
Private.2= c('0','1','0','0','0','0','1','0','0'))
df
how can i use pivot wider to summarize Public Private according Plant1 and 2? logical behind: every Plant element can only enrol either Public or Private plant 1 and Public.1 Private.1 correlated
Expected output:
plant1 plant2 Public Private
1 1 0 1 0
2 0 1 0 1
3 1 0 1 0
4 0 1 1 0
5 0 1 1 0
6 1 0 0 1
7 0 1 0 1
8 0 1 1 0
9 1 0 1 0