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.
Examples
x <- 'Shots were exchanged at the hospital'
mirror(x)
#> [1] "latipsoh eht ta degnahcxe erew stohS"
x <- c('Water', 'water', 'everywhere')
mirror(x)
#> [1] "retaW" "retaw" "erehwyreve"
# 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)
#> Warning: NAs introduced by coercion
#> [1] 95141.3 82817.2 NA
x <- data.frame(x=1:5, y=6:10)
mirror(x)
#> y x
#> 1 6 1
#> 2 7 2
#> 3 8 3
#> 4 9 4
#> 5 10 5
x <- matrix(1:10, nrow=2)
mirror(x)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 9 7 5 3 1
#> [2,] 10 8 6 4 2