Le 8 Octobre 2005 05:35, [EMAIL PROTECTED] a écrit : > Sam R. Smith a écrit : > > Hi, > > I have the following code to randomly generate the points: > > csr <-function(n=60){ > > x=runif(n) > > y=runif(n) > > f=cbind(x,y) > > } > > plot(csr()) > > > > I wonder how to code to make the first twenty points to be BLUE; second > > twenty points to be RED; the last twenty points to be GREEN? > > mynewfct = function(n=60) > { > x=runif(n) > y=runif(n) > f=cbind(x,y) > plot(f[1:20] , col='blue'); > par(new=T); > plot(f[21:40] , col='red'); > par(new=T); > plot(f[41:60] , col='green'); > } > > hih
This function will plot 60 points, no matter the value of argument 'n'. Building also on Jim Holtman's comment, may I rather suggest csr <- function(n=60) { x <- cbind(runif(n), runif(n)) plot(x, col=rep(c("blue", "red", "green"), each=20, length.out=n)) x # why not return the values... } HTH -- Vincent Goulet, Professeur agrégé École d'actuariat Université Laval, Québec [EMAIL PROTECTED] http://vgoulet.act.ulaval.ca ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html