I'm probably doing something stupid. However, I have a binary vector of length n. I'm trying to then apply an ifelse function depending on selected random values from the vector.
y <- sample(0:1, 500, replace = TRUE)
y
p=0.2
randomcells <- sample(1:length(y), 20)
randomcells
for (i in 1:length(y)){
if(!i %in% randomcells){
next
}
print(y[i])
print(ifelse(y[i]<-1,log((1-p)/p),log((p/1-p))))
}
}
I'd expect from running this code values that are y[i] = 0
to return a negative value else a positive value. Unfortunately, it currently only returns positive values regardless of the value of y[i]
. Any help is greatly appreciated.
Once this is done, I'm then looking to save positive values in one vector and negative values in the other, but those steps are proving difficult due to this current issue.
I really appreciate any help you can provide.
Sam
Aucun commentaire:
Enregistrer un commentaire