[R] Automating the job?

ben@zoo.ufl.edu ben at zoo.ufl.edu
Wed Feb 28 23:44:45 CET 2001



On Wed, 28 Feb 2001, Youngser Park wrote:

> Hi!
>
> I just started to use R recently, and would like to ask a help about
> automating the job.
>
> I need to use "kmeans" function with my own 300 data files, and wonder if
> it's possible to do it automatically. For example,
>
> > library (mva)
> > mydata <- read.table ("data1")
> > cl <- kmeans(mydata, 5, 20)
>
> and I just need to save "cl" info (i.e. the center info). Of course, I'll
> have the data from "data1" to "data300".
>
> Could someone please give me an advise how to do it, or any other
> recommendation for this job? I'll run this either in Unix or Mac environment
> using the version 1.2.1.

  This should be pretty straightforward.

library(mva)
maxit <- 20
nclust <- 5
nvars <- 5
npts <- 100
ndata <- 300
## cluster identity of each point, center of each cluster, size of each
## cluster
result.len <- npts+nclust*nvars+nclust
results <- matrix(ncol=result.len,nrow=ndata)
for (i in 1:ndata) {
  mydata <- read.table(paste("data",i,sep=""))
  results[i,] <- unlist(kmeans(mydata,nclust,maxit))
}

does that help?

>
> Thanks in advance.
>
> - Youngser Park
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
318 Carr Hall                                bolker at zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list