posixct

Adding missing rows

ぃ、小莉子 提交于 2019-12-17 16:26:30
问题 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 回答1: Try: ts = read.csv(file=pathfile, header=TRUE, sep=",",

Extracting time from POSIXct

血红的双手。 提交于 2019-12-17 15:13:55
问题 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

R as.POSIXct parsing error

左心房为你撑大大i 提交于 2019-12-17 14:53:51
问题 I am trying to parse a vector of time string and came across a strange error. For example, if I run the following section of code, R returned the result as expected. time_format="%m/%d/%Y %H:%M:%S" t_1 = "03/13/2011 01:00:10" as.POSIXct(t_1, format = time_format) Output: [1] "2011-03-13 01:00:10 EST" However, if I change the time slightly to 2 AM t_2 = "03/13/2011 02:00:10" as.POSIXct(t_2, format = time_format) The output became: [1] NA I can reproduce it on R 2.11.1 and 2.12.2 on Windows 7

Round a POSIX date (POSIXct) with base R functionality

心已入冬 提交于 2019-12-17 10:52:56
问题 I'm currently playing around a lot with dates and times for a package I'm building. Stumbling across this post reminded me again that it's generally not a bad idea to check out if something can be done with basic R features before turning to contrib packages. Thus, is it possible to round a date of class POSIXct with base R functionality? I checked methods(round) which "only" gave me [1] round.Date round.timeDate* Non-visible functions are asterisked This is what I'd like to do (Pseudo Code)

R: loss of precision when POSIXct binding with datetime (sql server) [duplicate]

对着背影说爱祢 提交于 2019-12-13 20:25:01
问题 This question already has answers here : Odd behavor with POSIXct/POSIXlt and subsecond accuracy (1 answer) R xts: .001 millisecond in index (2 answers) Closed 6 years ago . When working to update a sql server table with a datetime field, I had the following observations: > options(digits.secs = 3) > z <- strptime("20/2/06 11:16:16.68", "%d/%m/%y %H:%M:%OS") > z [1] "2006-02-20 11:16:16.67" > z <- strptime("20/2/06 11:16:16.683", "%d/%m/%y %H:%M:%OS") > z [1] "2006-02-20 11:16:16.682" We can

POSIXct times around DST?

半世苍凉 提交于 2019-12-13 14:20:41
问题 I want to subtract 1 day from a POSIX date and end up at the same time around DST. For example, when I add a day: > as.POSIXct('2009-03-08 23:00:00.000') + 86400 [1] "2009-03-09 23:00:00 EDT" But when I go past, it offsets: > as.POSIXct('2009-03-08 23:00:00.000') - 86400 [1] "2009-03-07 22:00:00 EST" What's the best way to deal with absolute time differences around DST? Usually I deal with this by converting the times into strings and dealing with them separately so that DST isn't applied.

How to get the beginning of the day in POSIXct

≯℡__Kan透↙ 提交于 2019-12-13 14:15:37
问题 My day starts at 2016-03-02 00:00:00 . Not 2016-03-02 00:00:01 . How do I get the beginning of the day in POSIXct in local time? My confusing probably comes from the fact that R sees this as the end-date of 2016-03-01? Given that R uses an ISO 8601? For example if I try to find the beginning of the day using Sys.Date(): as.POSIXct(Sys.Date(), tz = "CET") "2016-03-01 01:00:00 CET" Which is not correct - but are there other ways? I know I can hack my way out using a simple as.POSIXct(paste(Sys

Converting date and time with POSIX

喜欢而已 提交于 2019-12-13 12:48:18
问题 I have animal tracking data with position, date and time. I need to plot the data, time of day vs date/day, but I am struggling with getting the time and date in right format with the POSIX command. Here's my script up to the point where I have tried various ways using POSIX: library(chron) dtimes <- as.character(df$TimeWhen) dtparts <- t(as.data.frame((strsplit(dtimes,'T')))) rownames(dtparts) <- NULL colnames(dtparts) <- c("Date","Time") ... I need a column with dates and one with h:m:s in

How to plot when Date and hour in separate field using ggplot in R

我怕爱的太早我们不能终老 提交于 2019-12-12 20:41:06
问题 I have the following data frame head(d[, c(1,2,7)], 10) date hour total_sess 2 2014-04-06 00 115 3 2014-04-07 01 3 4 2014-04-07 16 3 5 2014-04-07 21 115 6 2014-04-08 00 115 7 2014-04-08 06 3 8 2014-04-09 05 3 9 2014-04-09 11 201 10 2014-04-09 14 3 11 2014-04-09 20 3 How do i use ggplot to plot a bar chart with X-Axis = hour (indicating date along the Axis) and Y Axis as total_sess I tried the following but was unable to generate a continuous flow ggplot(data = d, aes(x = hour, y = total_sess,

How to copy specific values from one data column to another while matching other columns in R?

对着背影说爱祢 提交于 2019-12-12 16:13:06
问题 I've searched a number of places (stackoverflow, r-blogger, etc), but haven't quite found a good option for doing this in R. Hopefully someone has some ideas. I have a set of environmental sampling data. The data includes a variety of fields (visit date, region, location, sample medium, sample component, result, etc.). Here's a subset of the pertinent fields. This is where I start... visit_date region location media component result 1990-08-20 LAKE 555723 water Mg *Nondetect 1999-07-01 HILL