Skip to content

Mean Help

6 messages · Hard Core, R. Michael Weylandt, Jessica Streicher

#
I have a dataframe.
Let's suppose that i have two columns. The first one contains height, the
second one contains eye color that can be Green, Blue or Brown.
I want to calculate the aritmetic mean of the height only for those people
who have Blue eyes. How can I do it?
Thank you for your availability.




--
View this message in context: http://r.789695.n4.nabble.com/Mean-Help-tp4648000.html
Sent from the R help mailing list archive at Nabble.com.
#
Many forms, but I'll recommend this one this time around:

aggregate(height ~ eyes, DATA, mean)

See ?aggregate for an explanation of what aggregate() does and
?formula for an explanation of the tilde syntax.

Note that this assumes your column names are "height" and "eyes."
Adjust as needed.

Michael
On Wed, Oct 31, 2012 at 1:18 PM, Hard Core <gioxc at hotmail.it> wrote:
#
please provide a bit of the dataframe in the future using the dput() function
height color
1       1  blue
2       2 green
3       3  blue
4       4 brown
5       5  blue
6       6 brown
7       7 green
8       8 brown
9       9 green
10     10 brown
height color
1      1  blue
3      3  blue
5      5  blue

should create a new dataframe with only those that have blue eyes, then
[1] 3

should provide you with the mean of those.
On 31.10.2012, at 14:18, Hard Core wrote:

            
#
On Wed, Oct 31, 2012 at 4:31 PM, Hard Core <gioxc at hotmail.it> wrote:
Assuming you're referring to my proposal of

aggregate(height ~ eyes, DATA, mean)

It's not blue eyes only: that will summarize height for each eye color
by taking the mean. Then just select blue eyes and you're good to go.

Finally, I note you're posting from Nabble. Please include context in
your reply -- I don't believe Nabble does this automatically, so
you'll need to manually include it. Most of the regular respondents on
this list don't use Nabble -- it is a _mailing list_ after all -- so
we don't get the forum view you do, only emails of the individual
posts. Combine that with the high volume of posts, and it's quite
difficult to trace a discussion if we all don't make sure to include
context. I'm only following up because I have a hunch this involves my
earlier reply, but it's really not clear.

Cheers,
Michael