-1

I have a large document-Term matrix.

I want to combine columns which with the same column name.

I have found someone asked the same problem and had work solution. Combine columns in matrix having same column name

I have tried using the answer to do.

But R returns an error message to me.

Error: cannot allocate vector of size 49.3 Gb

#my large matrix
tf_mat <- as.matrix(dtm_title) %>%
          cbind(as.matrix(dtm_abstract)) %>%
          cbind(as.matrix(dtm_claim)) 

#Combine columns with same column name.
nms <- colnames(tf_mat)
tf_mat %*% sapply(unique(nms),"==", nms)

Error: cannot allocate vector of size 49.3 Gb

Is there any way to solve it? Or is there any other solution?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Eva
  • 483
  • 1
  • 4
  • 13
  • Showing some sample data will get you more help. – Agaz Wani Aug 22 '17 at 03:13
  • 4
    There are lot of posts about solving the error you are facing. For example, [1](https://stackoverflow.com/questions/5171593/r-memory-management-cannot-allocate-vector-of-size-n-mb) , [2](https://stackoverflow.com/questions/10917532/r-memory-allocation-error-cannot-allocate-vector-of-size-75-1-mb) or [3](https://stackoverflow.com/questions/44169978/error-cannot-allocate-vector-of-size-1000-0-mb-r) . – Ronak Shah Aug 22 '17 at 03:26

1 Answers1

0

Thanks for all of your opinion.

I have tried use another way from Combine columns in matrix having same column name.

I think it's more suitable for my case, and don't take lot of time to execute.

nms <- colnames(tf_mat)
tf_mat_bind <- sapply(unique(nms), function(i)rowSums(tf_mat[, nms==i, drop=FALSE]))
Eva
  • 483
  • 1
  • 4
  • 13