how to convert matrix output from silhouette() to dataframe in r

181 views Asked by At

I ran kmeans. I applied silhouette() on it. is.matrix(sil.output) gives me back a TRUE.
so now I must believe I have a matrix. I want to convert it to a dataframe . but as.data.frame(sil.output) gives error below. how can I convert the output matrx to data frame.

Error in as.data.frame.default(sil) : 
  cannot coerce class ‘"silhouette"’ to a data.frame
1

There are 1 answers

0
Jonathan Marshall On

The trick is to use as.data.frame.matrix(sil.output).

Alternatively, you can use the other trick of as.data.frame(sil.output[]).

Both work as the underlying object is a matrix. It's just the class that is causing the issue.