DATA
v1 <- c("2015-01-05 15:00:00", "2015-01-05 15:45:00", "2015-01-05 15:00:30")
OPERATIONS
v2 <- strptime(v1, '%Y-%m-%d %H:%M:%S')
str(v2)
POSIXlt[1:3], format: "2015-01-05 15:00:00" "2015-01-05 15:45:00" "2015-01-05 15:00:30"
v3 <- v2[!v2$min] # create v3 from v2 eliminating min != 00
RESULT (successful subsetting)
str(v3)
POSIXlt[1:2], format: "2015-01-05 15:00:00" "2015-01-05 15:00:30"
Now creating v4 by coercing v2 to POSIXct (successful)
v4 <- as.POSIXct(v2, format = "%y/%m/%d %H:%M")
str(v4)
POSIXct[1:3], format: "2015-01-05 15:00:00" "2015-01-05 15:45:00" "2015-01-05 15:00:30"
OPERATION IN QUESTION - Applying the same subsetting operation to POSIXct as to POSIXlt causes the error below
v5 <- v4[!v4$min] # reassign v2 eliminating min != 00
RESULT (error)
Error in v4$min : $ operator is invalid for atomic vectors
QUESTIONS:
a) Why this difference in behavior?
b) What would be an equivalent operation to use with POSIXct?
Many thanks