posixct

Speedup conversion of 2 million rows of date strings to POSIX.ct

梦想的初衷 提交于 2019-11-28 09:13:32
I have a csv which includes about 2 million rows of date strings in the format: 2012/11/13 21:10:00 Lets call that csv$Date.and.Time I want to convert these dates (and their accompanying data) to xts as fast as possible I have written a script which performs the conversion just fine (see below), but it's terribly slow and I'd like to speed this up as much as possible. Here is my current methodology. Does anyone have any suggestions on how to make this faster? dt <- as.POSIXct(csv$Date.and.Time,tz="UTC") idx <- format(dt,tz=z,usetz=TRUE) So the script converts these date strings to POSIX.ct .

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

白昼怎懂夜的黑 提交于 2019-11-28 08:31:21
I have a data file which has three columns thus: 20010101 000000 0.833 20010101 000500 0.814 20010101 001000 0.794 20010101 001500 0.772 ... As is fairly clear to human eyes, the first two are date and time. I need to convert them into a POSIXct (or something else if it's better, but my limited past experience of dealing with timestamps in R is to use POSIXct). Normally, having pulled it in with read.table, I would use: df$DateTime <- as.POSIXct(paste(df$Date, df$Time), format="%Y%m%d %H%M%S") However, the second column seems to lose its leading zeroes (probably through a type coercion?), and

Round a POSIX date and time (posixct) to a date relative to a timezone

时光怂恿深爱的人放手 提交于 2019-11-28 08:23:26
问题 I want to round a POSIXct down to the day, relative to a specific timezone. If I try round(as.POSIXct("2013-03-05 23:00:00 EST"), "day") It returns 2013-03-06 Which makes sense, in that when it's 23:00:00 EST on 2013-03-05 in EST5EDT, it's already 2013-03-06 in UTC. Logically, what I want to do is: round(as.POSIXct("2013-03-05 23:00:00 EST"), "day", tz="EST5EDT") That is, "round this date and time to the nearest day, relative to the EST5EDT time zone". Unfortunately, round doesn't take a time

ifelse() stripping POSIXct attribute from vector of timestamps?

て烟熏妆下的殇ゞ 提交于 2019-11-28 07:31:32
问题 This is weird: R's ifelse() seems to do some (unwanted) casting: Lets say I have a vector of timestamps (possibly NA) and NA values should be treated differently than existing dates, for example, just ignored: formatString = "%Y-%m-%d %H:%M:%OS" timestamp = c(as.POSIXct(strptime("2000-01-01 12:00:00.000000", formatString)) + (1:3)*30, NA) Now timestamp #[1] "2000-01-01 12:00:30 CET" "2000-01-01 12:01:00 CET" "2000-01-01 12:01:30 CET" #[6] NA as desired but translation by 30 seconds results in

Convert Date to POSIXct

穿精又带淫゛_ 提交于 2019-11-28 03:29:40
问题 Why does the Date below change to "2014-07-07" when converted to POSIXct? Sys.setenv(TZ='America/Sao_Paulo') d <- as.Date("2014-07-08", format="%Y-%m-%d") d [1] "2014-07-08" as.POSIXct(d) [1] "2014-07-07 21:00:00 BRT" 回答1: Because as.POSIXct.Date doesn't look for a timezone (and won't pass it to .POSIXct if you specify it in ... ) and Date objects are "UTC", so your POSIXct is offset from the UTC of the Date object. It would be better to call as.POSIXct on the character string directly, if

Extracting time from POSIXct

不想你离开。 提交于 2019-11-28 03:22:32
How would I extract the time from a series of POSIXct objects discarding the date part? For instance, I have: times <- structure(c(1331086009.50098, 1331091427.42461, 1331252565.99979, 1331252675.81601, 1331262597.72474, 1331262641.11786, 1331269557.4059, 1331278779.26727, 1331448476.96126, 1331452596.13806), class = c("POSIXct", "POSIXt")) which corresponds to these dates: "2012-03-07 03:06:49 CET" "2012-03-07 04:37:07 CET" "2012-03-09 01:22:45 CET" "2012-03-09 01:24:35 CET" "2012-03-09 04:09:57 CET" "2012-03-09 04:10:41 CET" "2012-03-09 06:05:57 CET" "2012-03-09 08:39:39 CET" "2012-03-11 07

R: as.POSIXct timezone and scale_x_datetime issues in my dataset

被刻印的时光 ゝ 提交于 2019-11-28 02:55:51
问题 I spent some time trying to figure out why the hour ticks were shifted when scale_x_datetime was applied. I've tried to give the timezone when the Date/Time column was created. I used ggplot and scale_x_datetime() from the package scales. The hour ticks were wrong, which datapoint did not match the time in their Date/Time column. Here is some procedures to deal with my dataset. DF$DateTime<-as.POSIXct(DF$timestamp,format="%m/%d/%y %H:%M", tz="America/Toronto") DF$Date<-as.Date(DF$DateTime)

Converting numeric time to datetime POSIXct format in R

送分小仙女□ 提交于 2019-11-28 01:36:54
I have a data frame containing what should be a datetime column that has been read into R. The time values are appearing as numeric time as seen in the below data example. I would like to convert these into datetime POSIXct or POSIXlt format, so that date and time can be viewed. tdat <- c(974424L, 974430L, 974436L, 974442L, 974448L, 974454L, 974460L, 974466L, 974472L, 974478L, 974484L, 974490L, 974496L, 974502L, 974508L, 974514L, 974520L, 974526L, 974532L,974538L) 974424 should equate to 00:00:00 01/03/2011 , but the do not know the origin time of the numeric values (i.e. 1970-01-01 used below

Aggregate values of 15 minute steps to values of hourly steps

爷,独闯天下 提交于 2019-11-28 00:28:02
I have a data frame that looks like this: Timedate TotalSolar_MW 20 2013-06-01 04:45:00 13.0 21 2013-06-01 05:00:00 41.7 22 2013-06-01 05:15:00 81.8 23 2013-06-01 05:30:00 153.0 24 2013-06-01 05:45:00 270.7 25 2013-06-01 06:00:00 429.3 26 2013-06-01 06:15:00 535.4 "Timedate" is POSIXlt , and "Total_Solar" is numeric . The time steps are in 15 minute intervals from June 1, 0:00 to June 24, 24:00. Now I want to aggregate the quarter hourly data to hourly steps e.g. 2013-06-01 06:00:00 934.8MW (81.8MW + 153.0MW + 270.7MW + 429.3MW; from 05:15 to 06:00) I tried this with: Sum <-aggregate(Total

Adding missing rows

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 22:31:09
The format of my excel data file is: day value 01-01-2000 00:00:00 4 01-01-2000 00:01:00 3 01-01-2000 00:02:00 1 01-01-2000 00:04:00 1 I open my file with this: ts = read.csv(file=pathfile, header=TRUE, sep=",") How can I add additional rows with zero number in column “value” into the data frame. Output example: day value 01-01-2000 00:00:00 4 01-01-2000 00:01:00 3 01-01-2000 00:02:00 1 01-01-2000 00:03:00 0 01-01-2000 00:04:00 1 Try: ts = read.csv(file=pathfile, header=TRUE, sep=",", stringsAsFactors=F) ts.tmp = rbind(ts,list("01-01-2000 00:03:00",0)) ts.out = ts.tmp[order(ts.tmp$day),]