Re: [R] Partition data into clusters

From: Suhaila Zainudin <>
Date: Mon, 24 Mar 2008 20:49:45 -0700


Thanks for your reply. I have tried yr suggestions with success. TQVM.

I have another query, say I want to write each cluster into a csv file such as follows:

clus1 <- my.clusters[[1]]
write.csv(clus1, file = "clus1.csv")



clus10 <- my.clusters[[10]]
write.csv(clus10,file = "clus10.csv")

I can write the functions to do that for all 10 clusters by repeatedly calling write.csv as above. Is there a more elegant way of doing it by using a loop (for example).

for(i in 1:xx) {
clusn <- my.clusters[[n]]
write.csv(clusn, file = "clusn.csv")

I am trying something using list as well, as folows:

names( my.clusters ) <- paste('Cluster_',1:10, sep='')

Now I can use


The above will return all members of Cluster_1.

I have an idea to use lapply or sapply to do write.csv on each components(Cluster_1.....Cluster_n) from my.clusters, that will do the same as the loop example. Maybe this is the better way..

Any comments are appreciated.


        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 25 Mar 2008 - 03:53:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 25 Mar 2008 - 06:30:24 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive