0

I am trying to arrange a table with two columns :

                   V1    V2
1       F3_Ct10_1.sub  Ct10
2       F3_Ct10_2.sub  Ct10
3       F3_Ct10_3.sub  Ct10
4       F3_Ct11_1.sub  Ct11
5       F3_Ct11_2.sub  Ct11
6       F3_Ct11_3.sub  Ct11
7       F3_Ct12_1.sub  Ct12
8       F3_Ct12_2.sub  Ct12
9       F3_Ct12_3.sub  Ct12

The idea is to arrange my data by the column V2, joining all the V1 value in the same line (for a same V2 value).

My goal is :

     V1                V2              V3              V4
1  Ct10     F3_Ct10_1.sub   F3_Ct10_2.sub   F3_Ct10_3.sub
2  Ct11     F3_Ct11_1.sub   F3_Ct11_2.sub   F3_Ct11_3.sub
3  Ct12     F3_Ct12_1.sub   F3_Ct12_2.sub   F3_Ct12_3.sub
4  Ct13     F3_Ct13_1.sub   F3_Ct13_2.sub   F3_Ct13_3.sub

Given that there are not necessarily the same number of values... I had in mind the cast function of reshape2, but no solution for now.

Thanks for your suggestions.

  • It is a dupe. `df1 %>% mutate(rn = rowid(V2)) %>% pivot_wider(names_from = rn, values_from = V1)` – akrun Feb 02 '22 at 15:43

0 Answers0