what is the difference between ==1
and ==-1
in these following codes?
mydata1=data.frame(State=ifelse(sign(rnorm(6))==-1,"Mina","Mani"),Q1=sample(1:6))
mydata2= data.frame(State=ifelse(sign(rnorm(6))==1,"Mina","Mani"),Q1=sample(1:6))
the -1 is just an inversion of the TRUE/FALSE operator in your code.
You can reproduce your code with set.seed(x)
Sign() produces you 1 and -1, so if you take your example:
sign(rnorm(6))
[1] -1 -1 1 1 1 1
so if you take the equal operator, you just ask if it's -1 or 1. Actually you want to generate randomly the names in your code, so it doesn't make any difference. But for understanding here what happens if you switch the numbers:
set.seed((123))
sign(rnorm(6))==-1
[1] TRUE TRUE FALSE FALSE FALSE FALSE
set.seed((123))
sign(rnorm(6))==1
[1] FALSE FALSE TRUE TRUE TRUE TRUE
with this information your code proceeds