Re: [R] Partition data into clusters

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

Hi,

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

my.clusters$Cluster_1

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.

Thanks!

        [[alternative HTML version deleted]]



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. 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive