f_12_hour: Format 12 Hour Times

Description Usage Arguments Value Examples

View source: R/f_12_hour.R

Description

Format times to the typical 12 hour '

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
f_12_hour(x = Sys.time(), format = "%I:%M %p", pad.char = "", ...)

## Default S3 method:
f_12_hour(x, format = "%I:%M %p", pad.char = "", ...)

## S3 method for class 'integer'
f_12_hour(x, format = "%I:%M %p", pad.char = "", ...)

## S3 method for class 'numeric'
f_12_hour(x, format = "%I:%M %p", pad.char = "", ...)

## S3 method for class 'hms'
f_12_hour(x, format = "%I:%M %p", pad.char = "", ...)

ff_12_hour(format = "%I:%M %p", pad.char = "", ...)

Arguments

x

A vector of coercible times.

format

A character string specifying the time output format.

pad.char

A character to use for leading padding if lengths of output are unequal.

...

Other arguments passed to as.POSIXct.

Value

Returns a string of publication ready 12 hour time stamps.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
f_12_hour(Sys.time())
f_12_hour(Sys.time(), pad.char ='0')
f_12_hour(Sys.time(), pad.char =' ')
f_12_hour(Sys.time(), '%I:%M:%S %p')
f_12_hour(c(NA, 0:24), '%I %p')
set.seed(10)
times <- as.POSIXct(sample(seq_len(1e4), 12), origin = '1970-01-01')
paste(f_12_hour(range(times)), collapse = ' to ')
## Not run: 
library(tidyverse)

set.seed(10)
data_frame(
    time = as.POSIXct(sample(seq_len(1e4), 12), origin = '1970-01-01'),
    val = sample(1:20, length(time), TRUE)
) %>%
    mutate(prop = val/sum(val)) %>%
    ggplot(aes(time, prop)) +
        geom_line() +
        scale_x_time(labels = ff_12_hour(format = '%I %p')) +
        scale_y_continuous(labels = ff_prop2percent(digits = 0))

## End(Not run)

numform documentation built on Oct. 10, 2021, 1:10 a.m.