I want to split a matrix into two parts. I used following code
x <- matrix(rnorm(15),5,3)
idx <- rbinom(5,1,0.5)
split(x,idx)
However, I got two vector instead two matrix. I know if I convert x
to data.frame will get what I want. i.e.
x <- as.data.frame(matrix(rnorm(15),5,3))
idx <- rbinom(5,1,0.5)
split(x,idx)
I wonder is there any way without convert matrix into data frame and result still in the matrix format? And why this happened?