[R] Simulation
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Thu May 14 16:05:04 CEST 2009
Stefan Grosse wrote:
> Debbie Zhang schrieb:
>
>> Now, I am trying to obtain the sample variance (S^2) of the 1000 samples that I have generated before.
>>
>> I am wondering what command I should use in order to get the sample variance for all the 1000 samples.
>>
>>
>>
>> What I am capable of doing now is just typing in
>>
>> var(z[[1]])
>>
>> var(z[[2]]).....................
>>
>>
if you have the data produced the for loop way, i.e., as a list of
vectors, you can go the intuitive way:
vars = list()
for (i in 1:1000)
vars[[i]] = z[[i]]
or the unintuitive way:
vars = lapply(z, var)
if you have the data produced the matrix or replicate way (i.e., a
matrix with columns representing samples), you can go the intuitive way:
vars = c()
for (i in 1:1000)
vars[i] = var(z[,i])
or the unintuitive way:
vars = apply(z, 2, var)
consider reading an intro to r
unless you like to receive responses as the one below.
vQ
> Common please use the package brain 2.0.
More information about the R-help
mailing list