I don't really even know how to describe what is happening, other than that R knows the value of a variable, but then is applying it incorrectly inside a function. This is copied directly from my terminal:
> n2
[1] 4
> rnorm(n2)
[1] 0.379217 -1.519947 1.602527
> rnorm(4)
[1] -0.93154715 -0.82908620 0.55084001 0.09018763
R knows n2 = 4
, and it knows how to deal with rnorm(4)
, but somehow rnorm(n2)
is being read as rnorm(3)
.
Below is my full code. I set R to interpret a warning as an error to stop the loop where the problem occurs. After running this check the value of n2
, then see what rnorm(n2)
does.
rm(list = ls())
options(warn = 2)
iterations = 1
n = 10
proportions = seq(.3, .7, by = .1)
#stores
y = c()
position = 1
#set var ratio
parameter = 1.25
#loop over proportions
for(p in proportions){
n1 = p*n
n2 = n-n1
for(i in 1:iterations){
#new ys
newy1 = sqrt(parameter)*rnorm(n1)
newy0 = rnorm(n2)
newy = c(newy1, newy0)
y[position:(position+n-1)] = newy
position = position+n
}
}
I am running R 3.2.3 on Windows 7 64 bit.
Sorry it took me a bit to get the question straightened out. Long time user, first time poster.
Thanks