[R] apply
Rolf Turner
ro||turner @end|ng |rom po@teo@net
Sat Oct 5 01:14:35 CEST 2024
On Fri, 04 Oct 2024 11:16:45 -0700
Jeff Newmiller via R-help <r-help using r-project.org> wrote:
> Even if this is not a homework question, it smells like one. If you
> read the Posting Guide it warns you that homework is off-topic, so
> when you impose an arbitrary constraint like "must use specific
> unrelated function" we feel like you are either cheating or wasting
> our time, and it is up to you to explain why we should follow you
> down this rabbit hole, keeping in mind that statistics theory per-se
> is also off-topic here. You have yet to explain why you want to do
> this the hard way.
Well put, Jeff.
cheers,
Rolf
> On October 4, 2024 2:13:26 AM PDT, Steven Yen <syen04 using gmail.com>
> wrote:
> >Pardon me!!!
> >
> >What makes you think this is a homework question? You are not
> >obligated to respond if the question is not intelligent enough for
> >you.
> >
> >I did the following: two ways to calculate a covariance matrix but
> >wonder how I might replicate the results with "apply". I am not too
> >comfortable with the online do of apply.
> >
> >> set.seed(122345671) > n<-3 > x<-rnorm(n); x [1] 0.92098449
> >> 0.80940115
> >0.60374785 > cov1<-outer(x-mean(x),x-mean(x))/(n-1); cov1 [,1] [,2]
> >[,3] [1,] 0.0102159207 0.00224105983 -0.0124569805 [2,] 0.0022410598
> >0.00049161983 -0.0027326797 [3,] -0.0124569805 -0.00273267965
> >0.0151896601 > cov2<-(x-mean(x))%*%t((x-mean(x)))/(n-1); cov2 [,1]
> >[,2] [,3] [1,] 0.0102159207 0.00224105983 -0.0124569805 [2,]
> >0.0022410598 0.00049161983 -0.0027326797 [3,] -0.0124569805
> >-0.00273267965 0.0151896601 >
> >
> >On 10/4/2024 4:57 PM, Uwe Ligges wrote:
> >> Homework questions are not answered on this list.
> >>
> >> Best,
> >> Uwe Ligges
> >>
> >>
> >>
> >> On 04.10.2024 10:32, Steven Yen wrote:
> >>> The following line calculates standard deviations of a column
> >>> vector:
> >>>
> >>> se<-apply(dd,1,sd)
> >>>
> >>> How can I calculate the covariance matrix using apply? Thanks.
More information about the R-help
mailing list