R: Return the First and Last Part of an Object

head_tail {photobiology} | R Documentation

## Return the First and Last Part of an Object

### Description

Returns the first and last "parts" (rows or members) of a spectrum, dataframe, vector, function, table or ftable. In other words, the combined output from methods `head` and `tail`.

### Usage

    head_tail(x, n, ...)

    ## Default S3 method:
    head_tail(x, n = 3L, ...)

    ## S3 method for class 'data.frame'
    head_tail(x, n = 3L, ...)

    ## S3 method for class 'matrix'
    head_tail(x, n = 3L, ...)

    ## S3 method for class 'function'
    head_tail(x, n = 6L, ...)

    ## S3 method for class 'table'
    head_tail(x, n = 6L, ...)

    ## S3 method for class 'ftable'
    head_tail(x, n = 6L, ...)

### Arguments

`x` | an R object.
`n` | a single integer. If positive, half the size for the resulting object: number of elements for a vector (including lists), rows for a matrix or data frame or lines for a function, to be retained from each end. If negative, all but the n last and n first number of elements of x.
`...` | arguments to be passed to or from other methods.

### Details

The value returned by head_tail() is equivalent to row binding the the values returned by head() and tail(), although not implemented in this way. The same specializations as defined in package 'utils' for head() and tail() have been implemented.

### Value

An object (usually) like x but generally smaller. For ftable objects `x`, a transformed `format(x)`.

### Methods (by class)

- `default`: Default method

- `data.frame`: Specialization for `data.frame` objects

- `matrix`: Specialization for `matrix`

- `function`: Specialization for `function`

- `table`: Specialization for `table`

- `ftable`: Specialization for `ftable`

### Note

For some types of input, like functions, the output may be confusing, however, we have opted for consistency with existing functions. The code is in part a revision of that of head() and tail() from package 'utils'. I have been missing this method especially when checking spectral data, as both ends are of interest.

`head_tail()` methods for function, table and ftable classes, are wrappers for head() method.

### See Also

`head`, and compare the examples and the values returned to the examples below.

### Examples

    head_tail(letters)
    head_tail(letters, n = -6L)
    head_tail(freeny.x, n = 10L)
    head_tail(freeny.y)

    head_tail(stats::ftable(Titanic))

[Package photobiology version 0.9.21 Index]