I need to transpose (kind of rotation data 90 degrees clockwise) it from long to wide , and having something similar as below:
col_to_row a1 a2 b1 b2 c1 c2
1 letters a a b b c c
2 bin cat1 cat2 cat1 cat2 cat1 cat2
3 num1 1 2 3 4 5 6
4 num2 7 8 9 10 11 12
I tried to use dplyr and tidyverse function but could not get there.
I would have appreciated any suggestion.
Thank you.
In your end result, column a1 through c2 contain a mix of strings and integers. In a data frame, each column has to contain a single type of object (all strings, all integers, ...). Are you willing to have the integers converted to strings (e.g., 2 -> "2")?
Transpose your data frame using t(df) to rotate it 90 degrees. After transposing, set the column names by combining letters with 1:2 using paste0(df$letters, 1:2), which will give you the desired wide format.