I have a list of dgCMatrix objects, and I want to edit a specific vector within each object to have an iterative suffix, a new one for each object. My objects look like this: dgCMatrix Object within list
the vector I want to add a suffix to is the second dim name vector, the cell barcodes.
I've been trying to do it like this:
#give the cell names a unique suffix for each matrix
counter <- 0
my_sparse_matrices <- lapply(my_sparse_matrices, function(matrix) {
counter <<- counter + 1
colnames(matrix$`Gene Expression`) <- paste0(colnames(matrix$`Gene Expression`),"_",counter)
})
But this seems to save the changed vector to my_sparse_matrices, when really I want to change each vector within the already existing my_sparse_matrices object.
I am doing this because I am trying to aggregate all these single cell expression matrices into one rLiger object, which requires a list of sparse matrices. However, the cells cannot have the same name between matrices, hence the need for a unique suffix for each one. Can anyone help me out what I need to do to make this happen? I am still relatively new to using lapply.