0

I have this dataframe and I want to convert the values of the first column to another column. This is the data.frame :

    scheme          value
1   TS:VAT  FR46351273019
2 TS:REGNO 35124658210293

I tried to use dcast from the library reshape2 but the result was not satisfying :

> reshape2::dcast(lTS$Identifiers,value ~ scheme)
           value       TS:REGNO        TS:VAT
1 35124658210293 35124658210293          <NA>
2  FR46351273019           <NA> FR46351273019

I need the end result to look like this :

           TS:VAT       TS:REGNO
1   FR46351273019 35124658210293

Can you please help me ?

Nabil B.
  • 7
  • 1
  • 5
  • using `tidyr` could you do `pivot_wider(lTS$Identifiers, names_from = scheme, values_from = value)`? – Ben Oct 15 '19 at 13:37
  • It works, thank you – Nabil B. Oct 15 '19 at 13:45
  • Possible duplicate of [Reshaping data.frame from wide to long format](https://stackoverflow.com/questions/2185252/reshaping-data-frame-from-wide-to-long-format) – NelsonGon Oct 15 '19 at 13:45
  • 1
    Or duplicate of: https://stackoverflow.com/questions/5890584/how-to-reshape-data-from-long-to-wide-format – Ben Oct 15 '19 at 13:49
  • 2
    Possible duplicate of [How to reshape data from long to wide format](https://stackoverflow.com/questions/5890584/how-to-reshape-data-from-long-to-wide-format) – Ben Oct 15 '19 at 13:52
  • Can you add your solution as an answer so I can mark it as solved ? – Nabil B. Oct 15 '19 at 13:55

1 Answers1

0

How about

lTS$Identifiers %>%
    group_by(scheme) %>%
    spread(scheme, value)
user2474226
  • 1,472
  • 1
  • 9
  • 9