I am having a SingleCellExperiment (sce) object:

sce <- SingleCellExperiment(list(counts=UMI_count))

which has two dimensions:

[1] 46761 68027

When I am trying to get column sums for all rows the following does not work:

colSums(assay(sce), na.rm = FALSE, dims = 1)

Giving me an error:

Error in colSums(assay(sce)) : 'x' must be an array of at least two dimensions

Apparently the issue was already described:


However, I can not find the solution. Is there another way of getting sums of columns of either SingleCellExperiment object or just dgcMatrix?

  • $\begingroup$ Are you trying to get the sum of the rows or the columns? $\endgroup$
    – AudileF
    Dec 20, 2017 at 9:09
  • $\begingroup$ Did you check what does assay(sce) return? Which is the output of dim(assay(sce)) ? $\endgroup$
    – llrs
    Dec 21, 2017 at 8:17

1 Answer 1


Ultimately I just implemented it manually with the precursor to SingleCellExperiment matrix (UMI_count which is dgcMatrix type) object in the following way:

# Removing genes with 0 - counts in all of the columns
num_removed = 0
for(i in 1:nrow(UMI_count)) {
  idx = i - num_removed
  if(sum(UMI_count[idx,]) < 1) {
    UMI_count <- UMI_count[-idx,]
    num_removed = num_removed + 1

sce <- SingleCellExperiment(list(counts=UMI_count))

I am getting sums of the columns for each row and then filtering out rows with the sum < 1. So, sum function for the slices - rows (numeric type) is working.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.