Skip to content
Prev 181374 / 398502 Next

long format - find age when another variable is first 'high'

Depending on what you want (haven't checked the speed) you could try
this one where
we have changed the ldlc in the first row so that it has none > 130
for id=1 just to
illustrate that case as well:
+  ldlc=c(122, 120, 125, 105, 142, 160))
id age ldlc min_age
1  1   5  122    <NA>
2  1  10  120    <NA>
3  1  15  125    <NA>
4  2   4  105     7.0
5  2   7  142     7.0
6  3  12  160    12.0
id min_age
1  1    <NA>
2  2     7.0
3  3    12.0
id min(age)
1  2        7
2  3       12

See sqldf home page at:
http://sqldf.googlecode.com
On Mon, May 25, 2009 at 8:45 AM, David Freedman <3.14david at gmail.com> wrote: