This is my first post. Apologies in advance if my question is dumb. I’m new to programming.
Ok, So I have a a matrix(eBpvalues) in R that has 152720 rows and 2 columns.
I want to split into 10 separate matrices containing 15272 rows each.
I have tried this with:
> newmx <-split(as.data.frame(eBpvalues), rep(1:10, each = 15272)))
> summary(newmx)
Length Class Mode
1 2 data.frame list
2 2 data.frame list
3 2 data.frame list
4 2 data.frame list
5 2 data.frame list
6 2 data.frame list
7 2 data.frame list
8 2 data.frame list
9 2 data.frame list
10 2 data.frame list
How would I go about joining these matrices side-by-side so I have a new matrix with 20 columns and 15272 rows?
Cheers,
Neil
You are almost there. An often used function in these situations is
do.call, which takes a function you want to apply and a list of data to apply it to. The function you want to apply iscbindto column bind the 10 data frames/matrices together.Taking you literally, we start with a matrix
mat(eBpvaluesin your Q), of appropriate size. Convert to a data frame:An easy way of producing an indicator factor is via the
gl()function:Then we have your
split()call:The last step is this, where we us
do.call()to applycbind()to the set of data frames innewMat:This gives us what you wanted (although you might need to tidy the column names up etc).