firstlastobs: Locate the index of the first/last unique value

Description Usage Arguments Details Value Author(s) Examples

Description

Locate the index of the first/last unique value in i) a vector or of a variable in a data frame.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
lastobs(x, ...)

firstobs(x, ...)

## Default S3 method:
lastobs(x, ...)

## Default S3 method:
firstobs(x, ...)

## S3 method for class 'formula'
lastobs(formula, data = parent.frame(), ...)

## S3 method for class 'formula'
firstobs(formula, data = parent.frame(), ...)

Arguments

x

A vector

...

Currently not used

formula

A formula (only the first term is used, see 'details').

data

A data frame

Details

If writing ~a + b + c as formula, then only a is considered.

Value

A vector.

Author(s)

Søren Højsgaard, [email protected]

Examples

1
2
3
4
5
6
7
8
9
x <- c(rep(1, 5), rep(2, 3), rep(3, 7), rep(1, 4))

firstobs(x)
lastobs(x)

data(dietox)

firstobs(~Pig, data=dietox)
lastobs(~Pig, data=dietox)

hojsgaard/doBy documentation built on Oct. 11, 2019, 9:55 a.m.