timegap | R Documentation |

`timegap`

indexes elements in a vector of ages such that the indexed
ages are spaced integer multiples of a time interval apart, to within a given
tolerance. `timegap.id`

is a wrapper to apply `timegap`

within levels
of factor `id`

. The selected ages can then be split into age groups the
specified time interval wide, ensuring that (virtually) every subject
has at most one measurement per interval.

```
timegap(age, gap, tol = 0.1 * gap, multiple = FALSE)
timegap.id(
age,
id,
data = parent.frame(),
gap,
tol = 0.1 * gap,
multiple = FALSE
)
diffid(
age,
id,
data = parent.frame(),
lag = 1,
differences = 1,
sort = FALSE,
keepNA = FALSE
)
```

`age` |
vector of ages. |

`gap` |
numeric, the required positive time gap between selected ages. |

`tol` |
numeric, the positive tolerance around the gap (default |

`multiple` |
logical, whether or not to return multiple solutions when found (default FALSE). |

`id` |
factor of subject ids. |

`data` |
data frame optionally containing |

`lag` |
an integer indicating which lag to use. |

`differences` |
an integer indicating the order of the difference. |

`sort` |
a logical indicating whether to first sort by id and age. |

`keepNA` |
a logical indicating whether to keep generated NAs. |

`timegap`

calculates all possible differences between pairs of ages,
expresses them as integer multiples of `gap`

, restricts them to
those within tolerance and identifies those providing the longest sequences.
For sequences of the same length, those with the smallest standard deviation
of successive differences (modulo the time interval) are selected.

With `timegap`

, for unique solutions, or multiple solutions with
`multiple FALSE`

, a vector of indices named with `age`

. With
`timegap.id`

the subject vectors are returned invisibly, concatenated.

With `multiple TRUE`

, where there are multiple solutions
they are returned as a named matrix.

`diffid`

returns `diff(age)`

applied within `id`

.
With `keepNA`

TRUE a suitable number of `NA`

s are added at the end,
while if FALSE all `NA`

s are omitted.

Tim Cole tim.cole@ucl.ac.uk

```
data(heights)
## bin age into 1-year groups by id
## gives multiple measurements per id per year
with(heights, table(floor(age), id))
## now select heights measured multiples of 1 year apart
(tg1 <- timegap.id(age, id, heights, 1))
## no more than one measurement per id per year
with(heights[tg1, ], table(floor(age), id))
## most time intervals close to 1 year
summary(diffid(age, id, heights[tg1, ], lag=1))
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.