1
votes

I'm working on bioinformatic data, and the object I have generated so far in a large dgTMatrix which I'm trying to export into a csv file I could open and check regardless of the size.

I'm working with R, and when I write the line

write.csv(A.data, "Adata.csv")

I get the following error:

Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class "structure("dgTMatrix", package = "Matrix")" to a data.frame

From what I understand, a dgTMatrix might not be directly convertible into a classic table, but I cannot find what extra step I need to nail to be able to have my csv file in the end.

Any help and pointers would be greatly appreciated!

1
@RobertMc this actually doesn't seem to be applicable in my case. I get the following sum objet: Length Class Mode 1 seurat S4 - PaulineM

1 Answers

0
votes

If A.data is a sparse matrix, meaning, an object such that class()returns

class(A.data)
#[1] "dgTMatrix"
#attr(,"package")
#[1] "Matrix"

then you need to coerce it to class "matrix" or class "data.frame" before writing to disk with write.csv2.

A.data<-as.matrix(A.data)
write.csv2(A.data, "Adata.csv")