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

firstlastobs {doBy} | R Documentation

## Locate the index of the first/last unique value

### Description

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

### Usage

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

### Arguments

`x` | A vector
`formula` | A formula (only the first term is used, see 'details').
`data` | A data frame
`...` | Currently not used

### Details

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

### Value

A vector.

### Author(s)

Søren Højsgaard, sorenh@math.aau.dk

### Examples

    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)

[Package doBy version 4.5-15 Index]