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.

______________________________________________
R-help@r-project.org 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.

Reply via email to