I'm generating a random numbers x,y between -10 and 10
then I create an if statement to classify each pair(x,y) in 4 quadrant in the following if statement
but the column quad give me all 4
so why?
then I create an if statement to classify each pair(x,y) in 4 quadrant in the following if statement
but the column quad give me all 4
so why?
Code:
x <- runif(n=400, min = -10, max = +10)
y <- runif(n=400, min = -10, max = +10)
mydata=cbind(x,y)
mydata=as.data.frame(mydata)
plot(x,y)
Code:
for(i in 1:400){
if((0< mydata$x[i] & mydata$x[i] <10) & (0< mydata$y[i] & mydata$y[i] <10)){
mydata$quad=1
}else
if((0<mydata$x[i] & mydata$x[i]<10) & (-10<mydata$y[i] & mydata$y[i]<0)){
mydata$quad=2
}else
if((-10<mydata$x[i] & mydata$x[i]<0) & (-10<mydata$y[i] & mydata$y[i]<0)){
mydata$quad=3
}else
if((-10<mydata$x[i] &mydata$x[i]<0) & (0<mydata$y[i] & mydata$y[i]<10)){
mydata$quad=4
}}