[R] Using tapply

From: Patrick Hausmann <Patrick.Hausmann_at_uni-bremen.de>
Date: Thu, 15 May 2008 11:05:44 +0200


Dear list,

I have a dataframe like this:

w <- c(1.2, 1.34, 2.34, 3.12, 2.43, 1.99, 2.01, 2.23, 1.45, 1.59) g <- rep(c("a", "b"), each=5)
df <- data.frame(g, w)
df

> df

    g w

1  a 1.20
2  a 1.34
3  a 2.34
4  a 3.12
5  a 2.43
6  b 1.99
7  b 2.01
8  b 2.23
9  b 1.45
10 b 1.59

Using tapply to get the mean for each group:

vk <- tapply(df$w, df$g, mean)
vk

#> vk
#    a     b
#2.086 1.854

Now I would like to get for each group the first value *greater* than the mean.
So for "a" it should be 2.34 and for "b" 1.99.

Thanks for any help
Patrick



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. Received on Thu 15 May 2008 - 13:44:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 15 May 2008 - 15:30:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive