BoltzmannBrain
BoltzmannBrain

Reputation: 5392

R strftime() only preserving date, not time

My R script reads in CSV data of two columns, where the columns are timestamps and scalar values, with:

data = read.csv(dataFilePath, colClasses=c("charDate", "numeric"))

My timestamps are formatted e.g. "5/14/14 13:14". The class charDate is defined to convert the timestamps:

setClass("charDate")
setAs("character", "charDate", function(from) strftime(from))

The datafiles I'm running are here. They all read in as expected, represented in the R dataframe data as e.g. "2014-05-14 13:14:00", except for those in the realTweets/ directory. Why? For realTweets/, the timestamps in data look like e.g. "2014-05-14", where the time info has not been preserved.

Upvotes: 0

Views: 127

Answers (1)

BoltzmannBrain
BoltzmannBrain

Reputation: 5392

The issue was with strftime(). As explained in this answer, strftime() just wraps as.POSIXlt(). Using as.POSIXlt() directly fixed my problem:

setAs("character", "charDate", function(from) as.POSIXlt(from))

Upvotes: 1

Related Questions