Anup Menon Nandialath wrote:
>
> I have a basic question with R. I'm generating a set
> of random variables and then combining them using the
> cbind statement. The code for that is given below.
>
> for (i in 1:100)
> {
> y <- rpois(i,lambda=10)
> X0 <- seq(1,1,length=i)
> X1 <- rnorm(i,mean=5,sd=10)
> X2 <- rnorm(i,mean=17,sd=12)
> X3 <- rnorm(i,mean=3, sd=24)
> ind <- rep(1:5,20)
> }
>
> data100 <- cbind(y,X0,X1,X2,X3,ind)
>
First, why the loop? For i in 1:99, this code is a waste
of computer time. The code should be:
i <- 100
y <- rpois(i,lambda=10)
X0 <- seq(1,1,length=i)
X1 <- rnorm(i,mean=5,sd=10)
X2 <- rnorm(i,mean=17,sd=12)
X3 <- rnorm(i,mean=3, sd=24)
ind <- rep(1:5,20)
data100 <- cbind(y,X0,X1,X2,X3,ind)
> but when i look at the data100 table, the y values now
> take the observation count.
The y values should be the same as y. y is a (random)
array of integers.
Alberto Monteiro
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.