[R] Mean Help

Jessica Streicher j.streicher at micromata.de
Wed Oct 31 16:30:37 CET 2012


please provide a bit of the dataframe in the future using the dput() function

> x<-data.frame(height=1:10, color=sample(c("blue","green","brown"),10,replace=T))
> x
   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

> blue.eyes <- x[x$color=="blue", ]
> blue.eyes
  height color
1      1  blue
3      3  blue
5      5  blue

should create a new dataframe with only those that have blue eyes, then

> mean(blue.eyes$height)
[1] 3

should provide you with the mean of those.

On 31.10.2012, at 14:18, Hard Core wrote:

> 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.
> 
> ______________________________________________
> 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.




More information about the R-help mailing list