exporting clustering results to table
Martin,
The cutree() function returns the cluster membership as a vector.
To get a similar result from pam() (and other functions in library
cluster) you need to extract the component $clustering, e.g.
> clustersA <- pam(distances, nkA, diss=TRUE)
> filenameclu = paste("filenameclu", ".txt")
> write.table(clustersA$clustering, file=filenameclu,sep=",")
Note the $clustering appended to the pam object.
Dave R.
Martin Tomko wrote:
Hello list,
the following approach did not work:
clustersA <- pam(distances, nkA, diss=TRUE);
gc();
filenameclu = paste("filenameclu", ".txt");
write.table(clustersA , file=filenameclu,sep=",");
although it worked with
clustersA <- hclust(distances, method="ward");
and a consecutive
kclassA <- cutree(clustersA, k=nkA);
filename = paste("clusters", ".txt");
write.table(kclassA,file=filename,sep=",",col.names=TRUE,row.names=TRUE);
Is there a <em>generic</em> method to export cluster object? I know that
pam is different (cluster object and some more data)- how can I extract
& export the clustering into a table with two columns, ID =
dissimilarity matrix row, and cluster = number of the cluster?
I waas using sink to get the data, but for large matrices it involves a
huge amount of manual formatting afterwards, let's say in excel.
Thanks many times
Martin
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.