[R] Problems with sample variance

Peter Alspach
Thu, 21 May 2009 03:55:38 -0000

Tena koe Chloe

Try

var(r)

BTW, it is better to use more than single letters in name your objects
to reduce the chance of conflicting with a standard R object.

HTH ...

Peter Alspach

> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Chloe Smith
> Sent: Thursday, 21 May 2009 12:33 p.m.
> To: r-help at r-project.org
> Subject: [R] Problems with sample variance
>
>
> Dear R users,
>
> I am a beginner to R. I generated 1000 samples with 15 data
> in each sample
>
> I tried finding the variance for each sample
>
> I used the code:
>
> m=1000;n=15
> > r<-rnorm(15000)
> > for(i in 1:m){
> x=data[,i]
> v=var(x)}
>
> what I got was just the variance for the last sample i.e. the
> 1000th sample
>
> but what I want is 1000 variance.
>
> Does anyone know what I did wrong?
>
> Thanks
>
> Chloe Smith
>
> --
> View this message in context:
> http://www.nabble.com/Problems-with-sample-variance-tp23645919
> p23645919.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>

The contents of this e-mail are confidential and may be subject to legal
privilege.
 If you are not the intended recipient you must not use, disseminate, distribute
or
 reproduce all or any part of this e-mail or attachments.  If you have received
this
 e-mail in error, please notify the sender and delete all material pertaining to
this
 e-mail.  Any opinion or views expressed in this e-mail are those of the
individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.