Let's suppose I have the following dataframe:
df = data.frame(Value = rnorm(16,0,1), stringsAsFactors = F)
I want to reshape this single column in order to get 4 columns where the first 4 rows of df are the first row of the new df, the rows from 5 to 8 are the second row of the new df, etc.
The desired output would then be:
# original random data
Value
1 0.91252514
2 0.54858410
3 0.60361002
4 -0.36479957
5 -0.57253378
6 -0.64271622
7 1.06519500
8 1.49557598
9 0.51933447
10 1.04606789
11 0.13745408
12 0.43722826
13 -0.01168782
14 -0.50464089
15 -0.82506265
16 -1.04228086
# desired output
Col1 Col2 Col3 Col4
1 0.91252514 0.54858410 0.60361002 -0.36479957
2 -0.57253378 -0.64271622 1.06519500 1.49557598
3 0.51933447 1.04606789 0.13745408 0.43722826
4 -0.01168782 -0.50464089 -0.82506265 -1.04228086
I tried this but I can't get what I need:
library(tidyr)
df2 = cbind(data.frame(Group= rep(c(1,2,3,4), length(df)/4),stringsAsFactors = F),df)
df2 %>% separate(Group, c("Beta","SE","t","p"))
Can anyone help me?
Thanks!