[R] Mean Help

arun smartpink111 at yahoo.com
Wed Oct 31 18:13:15 CET 2012


# [1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE # Returns a logical vector which checks whether each row of 2nd column of dat1 is "Blue" or not.
dat1[,1][dat1[,2]=="Blue"] #gives me values of 1st column where the index (logical vector) is TRUE.
#[1] 156 177 179 170

If I use,
dat1[dat1[,2]=="Blue",] #returns the subset of data with all the columns of dat1
 # Height EyeColor
#5    156     Blue
#6    177     Blue
#7    179     Blue
#8    170     Blue

mean(dat1[,1][dat1[,2]=="Blue"]) gives the mean of those values I mentioned above.
#[1] 170.5


----- Original Message -----
From: Hard Core <gioxc at hotmail.it>
To: r-help at r-project.org
Sent: Wednesday, October 31, 2012 11:19 AM
Subject: Re: [R] Mean Help

Thank you ... can you explain what you've done?

View this message in context: http://r.789695.n4.nabble.com/Mean-Help-tp4648000p4648013.html
Sent from the R help mailing list archive at Nabble.com.

R-help at r-project.org mailing list
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