ez.time: convert to time

View source: R/basic.R

ez.timeR Documentation

convert to time

Description

convert from a time (numeric, character/factor, hms/difftime) to class (chron) times (17:48:00–h:m:s military only) or to class numeric (0.7416667–fractions of a day), call times:

SPSS military time (civilian time not supported) specified in date format, 17:48 read into R as 64080 (seconds of a day, foreign package), or as hms/difftime (same as SPSS, haven package), or

Excel military/civilian time specified in time format, 5:48:00 PM, 17:48:00 read into R as 0.7416667 (fractions of a day), or

Pass directly a string "17:48:00" (format specified by param format)

Usage

ez.time(x, ori = "SPSS", format = "%H:%M", out.type = "numeric", ...)

Arguments

x

a vector of number or character, hms/difftime

ori

one of 'Excel', 'SPSS' (ignored if x is character)

format

input format, see examples (more formats at strptime). ignored if x is numeric/hms

out.type

string, 'numeric' (fractions of a day) or 'times'/'time'

Value

returns a vector of number (class numeric) or time (class times). class times can be passed to as.character(.), or substr(.,1,5), or as.numeric(.), see more at chron chron stores as a fraction of a day, if you do as.numeric

See Also

ez.date ez.is.date ez.is.date.like ez.age ez.time

Examples

ez.time("5:20:31 am",format="%I:%M:%S %p",out.type="time")  # 5, 05; am AM aM Am OK. %I = 12 hr
ez.time("15:32", format="%H:%M",out.type="time")  # 5 05 OK.
ez.time("5:2", format="%H:%M",out.type="time")

jerryzhujian9/ezmisc documentation built on March 9, 2024, 12:44 a.m.