posixct

Determine season from Date using lubridate in R

百般思念 提交于 2019-12-03 16:19:02
I have a very big dataset with a DateTime Column containing POSIXct-Values. I need to determine the season (Winter - Summer) based on the DateTime column. I've created a function which works fine on a small dataset, but crashes when I use it on the large one. Can anybody see my mistake? I've created 4 functions: 3 subfunctions so that I can do logical comparisons and selection using *apply functions 1 function to determine the season Here are thefunctions: require(lubridate) # function for logical comparison (to be used in *apply) greaterOrEqual <- function(x,y){ ifelse(x >= y,T,F) } #

How to convert specific time format to timestamp in R? [duplicate]

岁酱吖の 提交于 2019-12-03 15:24:15
This question already has answers here : Read csv with dates and numbers (3 answers) I am working on "Localization Data for Person Activity Data Set" dataset from UCI and in this data set there is a column of date and time(both in one column) with following format: 27.05.2009 14:03:25:777 27.05.2009 14:03:25:183 27.05.2009 14:03:25:210 27.05.2009 14:03:25:237 ... I am wondering if there is anyway to convert this column to timestamp using R. Waldir Leoncio First of all, we need to substitute the colon separating the milliseconds from the seconds to a dot, otherwise the final step won't work

Is there a specific way to handle timestamp columns in R when pulling data using RPostgreSQL?

故事扮演 提交于 2019-12-03 13:13:32
I'm trying to pull data from a PostgreSQL database and the results for a timestamp field are inconsistent. I'm not sure if I'm handling POSIXct results properly. Otherwise, I think I found a bug in the RPostgreSQL package. Here is the way to replicate the issue: Suppose there is a table in a postgres database with one field (run this in PostgreSQL): CREATE DATABASE mydb; CREATE TABLE test_table ( "DateTime" timestamp without time zone NOT NULL, CONSTRAINT "pk_test_table" PRIMARY KEY ("DateTime") ) WITH ( OIDS=FALSE ); ALTER TABLE test_table OWNER TO postgres; And let’s say there are a few

How to expand Posixct field in R str()?

血红的双手。 提交于 2019-12-03 11:14:15
I am trying to expand the amount of factors shown in one custom Posixct field where the normal way ( str(DF, list.len=ncol(DF), vec.len=20) ) does not work. I request here 20 but it shows all the time two ( "2017-01-01 08:40:00" "2017-01-01 08:50:00" ... ) regardless the length of the list (here 3 ). Data data.csv "AAA", "BBB" 1, 01012017-0940+0100 2, 01012017-0950+0100 3, 01012017-0838+0100 Code library('methods') # setClass # https://unix.stackexchange.com/a/363290/16920 setClass('iso8601') # https://stackoverflow.com/questions/5788117/only-read-limited-number-of-columns setAs("character",

How do I convert correctly timezones

こ雲淡風輕ζ 提交于 2019-12-03 08:59:46
I am using the fasttime package for its fastPOSIXct function that can read character datetimes very efficiently. My problem is that it can only read character datetimes THAT ARE EXPRESSED IN GMT. R) fastPOSIXct("2010-03-15 12:37:17.223",tz="GMT") #very fast [1] "2010-03-15 12:31:16.223 GMT" R) as.POSIXct("2010-03-15 12:37:17.223",tz="GMT") #very slow [1] "2010-03-15 12:31:16.223 GMT" Now, say I have a file with datetimes expressed in "America/Montral" timezone, the plan is to load them (implicitely pretending they are in GMT) and modifying subsequently the timezone attribute without changing

Modifying timezone of a POSIXct object without changing the display

这一生的挚爱 提交于 2019-12-02 23:56:35
I have a POSIXct object and would like to change it's tz attribute WITHOUT R to interpret it (interpret it would mean to change how the datetime is displayed on the screen). Some background: I am using the fasttime package from S.Urbanek, which take strings and cast it to POSIXct very quickly. Problem is that the string should represent a datetime in "GMT" and it's not the case of my data. I end up with a POSIXct object with tz=GMT , in reality it is tz=GMT+1 , if I change the timezone with attr(datetime, "tzone") <- "Europe/Paris"; datetime <- .POSIXct(datetime,tz="Europe/Paris"); then it

How to combine R dataframes based constraints on a time column

爱⌒轻易说出口 提交于 2019-12-02 06:30:50
问题 I have two R tables, each with a list of users and a timestamp corresponding to the time that they took a certain action. The first of these ( df1 ) two tables has an exhaustive list of the users, and users will have multiple rows with different timestamps. The second ( df2 ) will have a more limited list of users, but again users will be in the table multiple times with different timestamps. What I'd like to be able to do is join the two tables and end up with a table that matched the user

How to extract correct date from POSIXct element? [duplicate]

守給你的承諾、 提交于 2019-12-02 05:11:44
This question already has an answer here: Date conversion from POSIXct to Date in R 3 answers How can I get the correct date from the first column in my code? test <- data.frame(posixdate = c("2013-05-01 00:59:00", "2013-05-01 01:59:00", "2013-05-01 02:59:00", "2013-05-01 03:59:00")) test$posixdate <- as.POSIXct(test$posixdate, format="%Y-%m-%d %H:%M:%S" ) test$date <- as.Date(test$posixdate) The above code results in: posixdate date 1 2013-05-01 00:59:00 2013-04-30 2 2013-05-01 01:59:00 2013-04-30 3 2013-05-01 02:59:00 2013-05-01 4 2013-05-01 03:59:00 2013-05-01 The first two dates are not

POSIXct date conversion error [duplicate]

你离开我真会死。 提交于 2019-12-02 04:43:12
问题 This question already has an answer here : R: strptime() and is.na () unexpected results (1 answer) Closed 4 years ago . I've encountered the following error when converting a set of dates in character format to a POSIXct object. Example Data: t<-c("3/11/2007 1:30", "3/11/2007 2:00", "4/11/2007 2:00") str(t) chr [1:3] "3/11/2007 1:30" "3/11/2007 2:00" "4/11/2007 2:00" z<-as.POSIXct(strptime(t, format ="%m/%d/%Y %H:%M")) z "2007-03-11 01:30:00 MST" NA "2007-04-11 02:00:00 MDT" str(z) POSIXct[1

How to extract correct date from POSIXct element? [duplicate]

最后都变了- 提交于 2019-12-02 04:22:30
问题 This question already has answers here : Date conversion from POSIXct to Date in R (3 answers) Closed 4 years ago . How can I get the correct date from the first column in my code? test <- data.frame(posixdate = c("2013-05-01 00:59:00", "2013-05-01 01:59:00", "2013-05-01 02:59:00", "2013-05-01 03:59:00")) test$posixdate <- as.POSIXct(test$posixdate, format="%Y-%m-%d %H:%M:%S" ) test$date <- as.Date(test$posixdate) The above code results in: posixdate date 1 2013-05-01 00:59:00 2013-04-30 2