I’m working in R.
how can I transpose my table creating new columns by client. The rows would be by idMarket and Section, and the other columns would give the Score of each client in those Markets and Section.
idMarket idSection idClient Score %
2 99 23 100 1
2 99 56 25 0,2
3 67 23 56 0,5
3 67 56 50 0,3
Expected table:
idMarket idSection Client23 %23 Client56 %56
2 99 100 1 25 0,2
3 67 56 0,5 50 0,3
Thanks!!
>Solution :
pivot_wider(df, c(idMarket, idSection), names_from = idClient, values_from = c(Score, `%`))
# A tibble: 2 x 6
idMarket idSection Score_23 Score_56 `%_23` `%_56`
<int> <int> <int> <int> <dbl> <dbl>
1 2 99 100 25 1 0.2
2 3 67 56 50 0.5 0.3
reshape(df, dir='wide', timevar = 'idClient', idvar = c('idMarket', 'idSection'), sep='_')
idMarket idSection Score_23 %_23 Score_56 %_56
1 2 99 100 1.0 25 0.2
3 3 67 56 0.5 50 0.3