mirror: Flip an object

View source: R/flip.r

mirrorR Documentation

Flip an object

Description

This function creates a "mirror" image of a character string, a number, a matrix, or a data frame. For example "Shots were exchanged at the hospital" becomes "latipsoh eht ta degnahcxe erew stohS' and 3.14159 becomes 95141.3. Data frames and matrices will be returned with the order of columns or order of rows reversed.

Usage

mirror(x, direction = "lr")

Arguments

x

A vector of numeric or character values, or a matrix or data frame.

direction

Only used if x is a matrix or data frame. Accepted values are 'lr' (left-right mirror) or 'ud' (up-down mirror).

Value

Object with same class as x.

Examples

x <- 'Shots were exchanged at the hospital'
mirror(x)

x <- c('Water', 'water', 'everywhere')
mirror(x)

# last value will return NA because the exponentiation does not 
# make sense when written backwards
x <- c(3.14159, 2.71828, 6.02214076e+23)

mirror(x)
x <- data.frame(x=1:5, y=6:10)
mirror(x)

x <- matrix(1:10, nrow=2)
mirror(x)

adamlilith/omnibus documentation built on April 12, 2024, 8:46 p.m.