Plz help me ;(( I lost 7 hours for thinking and doing this code ;( I need to create points.....20 points(dots). All these dots have to be in one graph... when i run this code....it gives me only one dote..... number<- (0,2,3,4,5,6,8) for (i in seq(1:20)) {rsidpVector=rsidp(i) mean(rsidpVector) plot (length(rsidpVector), mean(rsidpVector), ylab="sample mean", xlab"sample size") } rsidp<- function(x){ i+0 {y<-sample(number,x,replace = TRUE)} return(y) } -- View this message in context: http://r.789695.n4.nabble.com/wanna-create-all-points-tp4647494.html Sent from the R help mailing list archive at Nabble.com.
One dote......and its a last dote of the loop.... ;( -- View this message in context: http://r.789695.n4.nabble.com/wanna-create-all-points-tp4647494p4647495.html Sent from the R help mailing list archive at Nabble.com.
On Oct 25, 2012, at 8:49 PM, Rlotus wrote:> Plz help me ;(( I lost 7 hours for thinking and doing this code ;( I need to > create points.....20 points(dots). All these dots have to be in one graph... > when i run this code....it gives me only one dote.....You got twenty dots. It's just that they were on twenty separate plots.> > number<- (0,2,3,4,5,6,8)That line above is not valid R code. You should have gotten an error> > for (i in seq(1:20)) > {rsidpVector=rsidp(i) > mean(rsidpVector) > plot (length(rsidpVector), mean(rsidpVector), ylab="sample mean", xlab> "sample size") > }You should define a function before it is called. It was only because I corrected the error in the assignment to "number" and ran it again that the function was available ... for plotting twenty separate points in twenty separate plots. number<- c(0,2,3,4,5,6,8) rsidp<- function(x){ i+0 # that line does nothing {y<-sample(number,x,replace = TRUE)} return(y) # that line only wastes time } plot(NA, xlim=c(1,20), ylim=range(number), ylab="sample mean", xlab "sample size") for (i in seq(1:20)) {rsidpVector=rsidp(i) mean(rsidpVector) # that line does nothing points (length(rsidpVector), mean(rsidpVector) ) }> > rsidp<- function(x){ > i+0 > {y<-sample(number,x,replace = TRUE)} > return(y) > } >-- David Winsemius, MD Alameda, CA, USA
Hello, You had enough answers to variants of this question to already know to open a graphics device once and _just_ once using plot() and then, in the loop, use points(). plot(1, type = "n", xlim = c(0, 20), ylim = c(0, 8), ylab="sample mean", xlab="sample size") for (i in seq(1:20)){ rsidpVector=rsidp(i) mean(rsidpVector) points(length(rsidpVector), mean(rsidpVector)) } And what's wrong with your "new" function rsidp()? What is i+0 supposed to do? Hope this helps, Em 26-10-2012 04:49, Rlotus escreveu:> Plz help me ;(( I lost 7 hours for thinking and doing this code ;( I need to > create points.....20 points(dots). All these dots have to be in one graph... > when i run this code....it gives me only one dote..... > > number<- (0,2,3,4,5,6,8) > > for (i in seq(1:20)) > {rsidpVector=rsidp(i) > mean(rsidpVector) > plot (length(rsidpVector), mean(rsidpVector), ylab="sample mean", xlab> "sample size") > } > > rsidp<- function(x){ > i+0 > {y<-sample(number,x,replace = TRUE)} > return(y) > } > > > > -- > View this message in context: http://r.789695.n4.nabble.com/wanna-create-all-points-tp4647494.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.