Re: [R] problem in my code

From: W. Yamamoto <wataru_at_crayon.se.uec.ac.jp>
Date: Mon 10 Jul 2006 - 14:22:35 EST

Hi,

How about replacing all "<<-" with "<-"? That error occured in
> membership[i] <<- 1

this line and this code stopped before
> cbind(x,y,membership)
this line.

Hope this may help you.

---
W. Yamamoto


> Dear R-users
>
> I wrote a small program for assigning a membership
>
> Here is my script
>
> sample.size <- 60
>
> x <- rnorm(sample.size, 0, 1)
> y <- rnorm(sample.size, 0, 1)
>
> x.mean <- mean(x)
> y.mean <- mean(y)
> membership <- numeric(sample.size)
>
> for (i in 1:sample.size)
> {
> if ((x[i] < x.mean) && (y[i] < y.mean))
> {
> membership[i] <<- 1
> } else {
> if ((x[i] > x.mean) && (y[i] < y.mean))
> {
> membership[i] <<- 2
> } else {
> if ((x[i] > x.mean) && (y[i] >
> y.mean))
> {
> membership[i] <<- 3
> } else
> {
> membership[i] <<- 4
> }
> }
>
> }
>
> }
> cbind(x,y,membership)
>
> There is an error message
> "Error: object "membership" not found"
> I can't figure it out.
>
> Any help or advice on improvement for this code will be appreciated.
> I konw this code is not well written at all.
>
> Thank you
>
> Taka
>
> ______________________________________________
> 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
>
>
______________________________________________ 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
Received on Mon Jul 10 14:27:10 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 10 Jul 2006 - 16:15:49 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.