Concatenating Matrices in R

前端 未结 2 944
说谎
说谎 2021-01-07 15:51

How can I concatenate matrices of same columns but different number of rows? For example, I want to concatenate a ( dim(a) = 15 7000 ) and b (dim(b) = 16

2条回答
  •  轮回少年
    2021-01-07 16:26

    cbindX from the package gdata combines multiple columns of differing column and row lengths. Check out the page here:

    http://hosho.ees.hokudai.ac.jp/~kubo/Rdoc/library/gdata/html/cbindX.html

    It takes multiple comma separated matrices and data.frames as input :) You just need to

    install.packages("gdata", dependencies=TRUE)

    and then

    library(gdata)
    concat_data <- cbindX(df1, df2, df3) # or cbindX(matrix1, matrix2, matrix3, matrix4)
    

提交回复
热议问题