renozao / NMF

NMF: A Flexible R package for Nonnegative Matrix Factorization
139 stars 41 forks source link

Error: NMF::nmf - Input matrix x contains at least one null or NA-filled row. #145

Open sophiegom opened 4 years ago

sophiegom commented 4 years ago

Hi all,

I am experiencing the following error:

Error: NMF::nmf - Input matrix x contains at least one null or NA-filled row.

The data frame I use was converted into a data frame from a dtm. I have checked other reported issues and incorporated the following code to check that both no all-zero and all-na rows and columns exist in my data:

# Remove rows with all 0 values
df.tdm.nmf.no.0 <- df.tdm.sparse[rowSums(df.tdm.sparse[, -1]) > 0, ]

# Remove rows with all NA values
df.tdm.nmf.no.na <- df.tdm.nmf.no.0[rowSums(is.na(df.tdm.nmf.no.0))==0,]
df.tdm.nmf <- df.tdm.nmf.no.na

# Remove columns with 0 or missing values 
i.0 <- which(colSums(df.tdm.nmf) == 0)
i.na <- which(colSums(is.na(df.tdm.nmf)) > 0)

Unfortunately this does not resolve the issue and I keep getting the error when running:

# Perform NMF
twt.res <- nmf(df.tdm.nmf[, c(i.0, i.na)], 5, 'brunet', seed = 123456)

Does anyone have any ideas on how to solve the issue? Would be much appreciated, thanks!

Please let me know if more info is required to answer this question.

ShixiangWang commented 4 years ago

The rowSum should not be 0