[R] Not the same length

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Wed Sep 18 19:07:38 CEST 2019


Redefining n is probably not a good idea...

[...snip...]
> m <-runif(n, 0, 5)
> n <-rnorm(n, 2, 3) 

Oops! n is now a vector of length 2000.

[...snip...]

> y_obs <- y_model +c( rnorm(n*0.97, 0, 0.1), rnorm(n*0.03, 0, 0.5) )

now length(n*0.97) == 2000 > 1, so rnorm(n*0.97, ...) gets you a length 2000 vector (check ?rnorm), and  c() of 2 of those is a vector of length 4000.

[...etc...]
>   
-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-help mailing list