i have imported csv file (excel) timestamp , value. efforts convert timestamp column usable time in r result in n/a. have looked @ several threads (so , elsewhere) , tried many suggestions somehow not managed right. have tried various simpler examples e.g. r-bloggers , have worked fine.
> dframe <- read.csv2("file.csv", dec=".", colclasses=c("character","numeric"), as.is=true)
> str(dframe)
'data.frame': 424 obs. of 2 variables: $ d: chr "2016.08.02 03:59:45" "2016.08.02 04:11:16" "2016.08.02 04:22:45" "2016.08.02 04:34:13" ... $ h: num 30 33.3 35.6 35.6 48.9 48.9 48.9 47.8 46.7 46.7 ...
this believe start. then:
> dframe$d <- as.posixct(dframe$d, tz="gmt", format="%y.%m.%d %h:%m:%s")
> str(dframe)
'data.frame': 424 obs. of 2 variables: $ d: posixct, format: na na na na ... $ h: num 30 33.3 35.6 35.6 48.9 48.9 48.9 47.8 46.7 46.7 ...
any suggestions welcome. aware of lubridate not trying it, while @ least.
try lubridate
multithreaded blas/lapack libraries detected. using 8 cores math algorithms. > library(lubridate) attaching package: ‘lubridate’ following object masked ‘package:base’: date > ymd_hms("2016.08.02 03:59:45") [1] "2016-08-02 03:59:45 utc" > str(ymd_hms("2016.08.02 03:59:45")) posixct[1:1], format: "2016-08-02 03:59:45"
"i aware of lubridate not trying it, while @ least." -- there reason not want to/can't use lubridate
? seems easy fix.
edit
i bored @ work today, decided give shot. reason posixct function failed because of "." have seperators. quick fix use gsub
replace "." "-". here example:
> s = c("2016.08.02 03:59:45", "2016.08.02 04:11:16", "2016.08.02 04:22:45", "2016.08.02 04:34:13") > dates = as.posixct(gsub(pattern="\\.", replacement="-", x=s)) > print(dates) [1] "2016-08-02 03:59:45 pdt" "2016-08-02 04:11:16 pdt" [3] "2016-08-02 04:22:45 pdt" "2016-08-02 04:34:13 pdt"
Comments
Post a Comment