---------- Forwarded message ----------
From: Ken Hutchison <vicvoncas...@gmail.com>
Date: Wed, Aug 24, 2011 at 6:06 PM
Subject: Re: [R] help with "by" command
To: amalka <ama...@gmail.com>


?tapply
or more specifically
?ave
 Hope this helps,
     Ken


On Wed, Aug 24, 2011 at 2:51 PM, amalka <ama...@gmail.com> wrote:

> Hello,
>
> I am a new user of R, and I'd be grateful if someone could help me with the
> following:
>
> I would like to compute the mean of variable "trust" in dataframe "foo",
> but
> separately for each level of variable V2.  That is, I'd like to compute the
> mean of trust at each level of V2.
>
> I have done this:
>
> > tmp <- by(foo, foo$V2, function(x) mean(foo$trust, na.rm=T))
> >tmp
>
> Doing this does indeed give me a mean for variable trust at each level of
> V2
> - but the problem is that I get the exact same mean for each level of V2.
> The means are not the really the same across levels of V2, but instead of
> getting the mean for each level of V2 I get the overall mean for the
> variable in the dataframe listed over and over for each level of V2.
>
> I have been attempting to figure this out for a while now, but I just can't
> seem to figure it out.
>
> Thanks for your time!
> Ari
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/help-with-by-command-tp3766285p3766285.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
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