Milliseconds in POSIXct Class

Specify the input format, using %OS to represent the seconds with their fractional parts. x <- c(“2014-02-24 11:30:00.123”, “2014-02-24 11:30:00.456”) y <- as.POSIXct(x, format = “%Y-%m-%d %H:%M:%OS”) When you come to display the value, append a number between 0 and 6 to the format string to tell R how many decimal places of seconds to … Read more

R – converting date and time fields to POSIXct with HHMMSS format

You were very close. The following “simply” forces the first two columns to be read as character strings, which saves the leading zeros. R> df <- read.table(text=”20010101 000000 0.833 20010101 000500 0.814 20010101 001000 0.794 20010101 001500 0.772″, + header=FALSE, colClasses=c(“character”, “character”, “numeric”), + col.names=c(“Date”, “Time”, “Val”)) R> df Date Time Val 1 20010101 000000 … Read more