Problem in row to column

Hi everyone, I'm new using R and I'm having some problem with my code.

I have a list columns data frame of some economic data like this:

#example data:
   date              account    value
   <list>             <list>  <int> <list>
 1 1st quarter      account1      1 
 2 2nd quarter      account1      2 
 3 3rd quarter      account1      3 
 4 4th quarter      account1      1 
 5 1st quarter      account2      2 
 6 2nd quarter      account2      3  
 7 3rd quarter      account2      1  
 8 4th quarter      account2      2  
 9 1st quarter      account3      1   
10 2nd quarter      account3      2  
11 3rd quarter      account3      1  
12 4th quarter      account3      3
.     .                .          .
.     .                .          . 
.     .                .          .

And I'm trying by 2 days to cross the data of the first column's rows to the columns, to get something like this:

#desired output:
account  1st quarter  2nd quarter  3rd quarter 4th quarter       sum
<list>  <int> <list> <int> <list> <int> <list> <int> <list> <int> <list>
account1     1            2            3            1             7
account2     2            3            1            2             8
account3     1            2            1            3             7 
   .         .            .            .            .             .
   .         .            .            .            .             .
   .         .            .            .            .             .

Does anyone knows how do this?

Like this:
Pivot data from long to wide — pivot_wider • tidyr (tidyverse.org)

1 Like

Thank you, you've solved my problem!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.