I am trying to split a dataframe vertically after certain column. Preferably by name. The first half of the split should remain a dataframe and the second should become a matrix. Here is an example.
pp <- rep(1:4,each=4)
cond <- rep(c("A","B"),each=2)
time <- rep(1:2,8)
value <- rnorm(16,1)
df <- data.frame(pp,cond,time,value)
as.data.frame(df %>%
pivot_wider(names_from = c(time), values_from = value))
pp cond 1 2
1 1 A 0.4121770 2.13178625
2 1 B 2.8638453 -0.64314357
3 2 A 2.2587738 1.74448028
4 2 B 0.2737670 0.89784427
5 3 A 0.5831763 2.37123498
6 3 B 0.5158274 1.40670718
7 4 A -0.6313988 1.06272354
8 4 B 2.0142500 0.01102302
Now I'd like to continue piping and split the cols pp and cond into a new dataframe and cols 1 and 2 into a matrix. Any suggestions?