Displaying 20 results from an estimated 7000 matches similar to: "day, month, year functions"
2020 Oct 23
2
The presence/absence of `zone` in POSIXlt depending on time zone as a cause of possible inconsistences?
Dear all,
I have just detected what seems a minor inconsistence with data types. If one unlists a POSIXlt time with GMT zone gets a numeric vector, since the POSIXlt list has no `zone` element, while if one unlists a POSIXlt time with a non GMT zone (also non specifying tz if the Sys.timezone is not GMT) gets a character vector due to including the `zone` element.
> x <-
2011 May 14
2
changing the day of the week in dates format
Dear all,
I have a question related to the POSIXlt function in R.
I have a set of dates and times, for exmaple:
startx <- as.POSIXct("2011-01-01 00:00:00")
finx <- as.POSIXct("2011-12-31 00:00:00")
daysx<- seq(startx, finx, by="24 hours")
I
want to change the dates of all the days falling on a Saturday to the
next working day (i.e. Monday). So I
2010 Dec 01
1
Changing the day of the month in a date
Hello, I want to change the day of the month in a date object. What I am
doing at the moment is:
x=as.POSIXlt(x)
x$mday=13
x=as.Date(x)
Does anybody know if there is a more "natural" (eficient) way to do this
Thank you
Felipe Parra
[[alternative HTML version deleted]]
2008 Feb 17
1
How to make a vector/list/array of POSIXlt object?
Hi Guys,
I'm cooking up my time series code. I want a data frame with first column as timestamp in POSIXlt format.
I hit on this the problem of how to create an array/list/vector of POSIXlt objects. Code is as follows
> dtt=array(dim = 2)
> t=as.POSIXlt( strptime("07/12/07 13:20:01", "%m/%d/%Y %H:%M:%S",tz="GMT"))
> dtt
[1] NA NA
> t
[1]
2011 May 24
2
Extracting day of month from Date objects
I've always found the chron library to be useful for
tasks like this:
> x <- round(runif(10)*100000, digits=0)
> y <- as.Date(x, origin="1970-01-01")
> library(chron)
> days(y)
[1] 7 25 26 25 10 24 1 31 12 8
31 Levels: 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < ... < 31
Notice that it returns the days as
2010 Sep 03
1
Incorrect formatted output after subtracting non-integer seconds from POSIXt origin
> x<-as.POSIXct("1970-1-1", tz="UTC")-.5
> y<-as.POSIXct("1970-1-1", tz="UTC")+.5
> x==y
[1] FALSE # of course
but x and y "appear" to be the same when formatted, even with extra
precision:
> format(x, format="%Y-%m-%d %H:%M:%OS2")
[1] "1970-01-01 00:00:00.50"
> format(y, format="%Y-%m-%d
2011 Jun 22
2
strange date problem - May 3, 1992 is NA
> is.na(strptime("5/2/1992", format="%m/%d/%Y"))
[1] FALSE
> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
[1] TRUE
Any idea what's going on with this? Running strptime against all dates
from around 1946, only 5/3/1992 was converted as "NA". Even stranger,
it still seems to have a value associated with it (even though is.na
thinks
2003 Jan 03
4
as.POSIXct problem?
Under
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status
major 1
minor 6.1
year 2002
month 11
day 01
language R
> x <- strptime(c('10/10/1969','12/31/2002'),format='%m/%d/%Y')
2005 Dec 19
3
given a mid-month date, get the month-end date
I have a vector of dates.
I wish to find the month end date for each.
Any suggestions?
e.g.
For 12/15/05, I want 12/31/05,
For 10/15/1995, I want 10/31/1995, etc
__________________________________________________
[[alternative HTML version deleted]]
2007 Sep 18
5
Need help on "date"
Dear all,
I have a variable 'x' like that:
> x
[1] "2005-09-01"
Here, 2005 represents year, 09 month and 01 day.
Now I want to create three variables naming: y, m, and d such that:
y = 2005
m = 09
d = 01
can anyone tell me how to do that?
Regards,
[[alternative HTML version deleted]]
2009 Jan 28
2
length of POSIXlt object (PR#13482)
The length() of a POSIXlt object is given as 9 regardless of the actual
length. For example:
> make.date.time
function (year=c(2006,2006),month=c(8,8),day=2:5,hour=13,minute=45)
{# convert year, etc., into POSIXlt object
#
d=as.character(make.date(year,month,day))
t=paste(hour,minute,sep=":")
as.POSIXlt(paste(d,t))
}
> t=make.date.time()
> t
[1] "2006-08-02 13:45:00"
2004 Feb 06
2
vector of factors to POSIXlt
hello,
I have a vector of factors
> str(rcptdt)
Factor w/ 51 levels "1/10/03","1/13/03",..:
> length(rcptdt)
[1] 87
which i want to convert to class POSIXlt to extract the day, so:
a1<-format(rcptdt,"%m/%d/%y")
> length(a1)
[1] 87
and:
a2<-strptime(a1, "%m/%d/%y")
str(a2)
`POSIXlt', format: chr [1:87] "2002-04-18"
2007 Jun 13
5
Confusion with sapply
Hi,
I have some confusion in applying a function over a column.
Here's my function. I just need to shift non-March month-ends to March
month-ends. Initially I tried seq.dates, but one cannot give a negative
increment (decrement) here.
return(as.Date(seq.dates(format(xdate,"%m/%d/%Y"),by="months",len=4)[4])
)
Hence this simple function:
> mydate <-
2004 May 06
3
strptime
Delving into the murky world of dates and times I found this:
dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")
> times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26")
> x <- paste(dates, times)
> z <- strptime(x, "%m/%d/%y
2004 Jun 07
7
Vectors of years, months, and days to dates?
The interface for dates in R is a little confusing to me.
I want to create a vector of Date objects from vectors of years, months, and
days.
One solution I found is:
years <- c(1991, 1992)
months <- c(1, 10)
days <- c(1, 2)
dates <- as.Date(ISOdate(years, months, days))
But, in this solution the ISOdate function converts the vectors into
characters,
which can cause serious
2007 Jul 17
1
problem with length()
In the following, can anyone tell me why length(eee) returns 9? I
was expecting 15398, and when I try to add this vector to a data
frame with that many rows, it fails complaining that the vector is of
length 9. In what I thought was an identical situation with a
related dataset, the same code worked as expected.
> length(fff)
[1] 15398
> str(fff)
int [1:15398] 20010102 20010102
2012 Feb 24
6
strange behaviour of "POSIXlt" "POSIXt" object
Hi,
Does anybody know why get I this kind of strange situation:
Browse[2]> hcEnd
[1] "2009-03-29 06:30:00"
Browse[2]> class(hcEnd)
[1] "POSIXlt" "POSIXt"
Browse[2]> is.na(hcEnd)
[1] TRUE
This issue is the source of my all issues in my program,
Thanks for your help
--
View this message in context:
2009 Jan 15
4
number of Mondays
dear All,
i'm trying to calculate the number of Mondays, Tuesdays, etc that each
month within a date range has. I have time series data that spans 60
months and i want to calculate the number of Mondays, Tuesdays, Wed,
etc of each month. (I want to control for weekly seasonality but my
data is monthly).
Is there an easy way to to this in R? or is there a package i could
use? i did
2013 Feb 19
5
Converting the data in year month day hour and minutes to date
Hi ,
I am trying to convert the date as factor to date using "as.date" function
in R. I have the date in the following format
2008-01-01 02:30
I tried to use the following command :
as.Date(mydata$Date, format="%y-%m-%d ")
Can somebody help me with this ? I was able to convert the format with no
hour but getting difficulty with hour included.
Thank you.
2008 Jan 01
1
How to convert day-month-year to Julian data number?
Hi,
Is there a package for converting day-month-year type date to julian
day number (JDN)? I looked around and I couldn't find any (I am pretty
new to R...)
Thanks and happy New Year to everybody!
H. N?zhet Dalfes
Professor,
Istanbul Technical University
Eurasia Institute of Earth Sciences
+90 (532) 206-1308
[dalfes at itu.edu.tr]