Learn R Programming

petersenlab (version 1.1.0)

convertHoursAMPM: Convert AM and PM Hours.

Description

Convert hours to 24-hour time.

Usage

convertHoursAMPM(hours, ampm, am = 0, pm = 1, treatMorningAsLate = FALSE)

Value

Hours in 24-hour-time.

Arguments

hours

The vector of times in hours.

ampm

Vector indicating whether given times are AM or PM.

am

Value indicating AM in ampm variable.

pm

Value indicating PM in ampm variable.

treatMorningAsLate

TRUE or FALSE indicating whether to treat morning times as late (e.g., 1 AM would be considered a late bedtime, i.e., 25 hours, not an early bedtime).

Details

Convert hours to the number of hours in 24-hour time. You can specify whether to treat morning hours (e.g., 1 AM) as late (25 H), e.g., for specifying late bedtimes

See Also

Other times: convertToHours(), convertToMinutes(), convertToSeconds()

Other conversion: convert.magic(), convertToHours(), convertToMinutes(), convertToSeconds(), percentileToTScore(), pom()

Examples

Run this code
# Prepare Data
df1 <- data.frame(hours = c(1, 1, 12, 12), ampm = c(0, 0, 1, 1))
df2 <- data.frame(hours = c(1, 1, 12, 12), ampm = c(1, 1, 0, 0))

# Convert AM and PM hours
convertHoursAMPM(hours = df1$hours, ampm = df1$ampm)
convertHoursAMPM(hours = df1$hours, ampm = df1$ampm,
  treatMorningAsLate = TRUE)

convertHoursAMPM(hours = df2$hours, ampm = df2$ampm, am = 1, pm = 0)
convertHoursAMPM(hours = df2$hours, ampm = df2$ampm, am = 1, pm = 0,
  treatMorningAsLate = TRUE)

Run the code above in your browser using DataLab