Displaying 20 results from an estimated 7000 matches similar to: "calculating the number of days from dates"
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
2008 Jan 02
3
Find missing days
Hi,
I have a data.frame like this:
y <- rnorm(60)
lev <- gl(3,20, labels=paste("lev", 1:3, sep=""))
date1 <- as.Date(seq(ISOdate(2007,9,1), ISOdate(2007,11,5),
by=60*60*24))
date1 <- date1[-c(3,4,15,34,38,40)]
df <- data.frame(lev=lev, date1=date1, y=y)
I would like to produce a new data.frame with missing days in df$date1
in each df$lev, like this:
lev
2005 Jul 19
2
Problems with date-format (R 2.1.1 + chron)
Hello,
today I've updated on the newest R-Version. But sadly a function I needed
didnt want to work:
The input is e.g.
days(as.Date("21-07-2005","%d-%m-%y"))
the error is: Fehler in Math.Date(dts): floor nicht definiert f??r Date
Objekte
(Error in Math.Date(dts): floor not defined for date objects)
Same for year. Only months gives me the correct output.
In Version
2003 Nov 14
5
ISOdate() and strptime()
Dear R-people!
I am using R 1.8.0, under Windows XP.
While using ISOdate() and strptime(), I noticed the following behaviour when
"wrong" arguments (e.g., months>12) are given to these functions:
> ISOdate(year=2003,month=2,day=20) #ok
[1] "2003-02-20 13:00:00 Westeurop?ische Normalzeit"
> ISOdate(year=2003,month=2,day=30) #wrong day, but returns a value
[1]
2007 May 10
3
Getting the last day of the month.
Hi,
Given a date, how do I get the last date of that month? I have
data in the form YYYYMM, that I've read as a date using
> x$Date <-
as.Date(ISOdate(substr(x$YearEnd,1,4),substr(x$YearEnd,5,6),1))
But this gives the first day of the month. To get the last day of the
month, I tried
> as.Date(as.yearmon(x$Date,frac=0))
But I don't get the last day of the month here. (Tried
2010 May 18
2
Function that is giving me a headache- any help appreciated (automatic read )
note: whole function is below- I am sure I am doing something silly.
when I use it like USGS(input="precipitation") it is choking on the
precip.1 <- subset(DF, precipitation!="NA")
b <- ddply(precip.1$precipitation, .(precip.1$gauge_name), cumsum)
DF.precip <- precip.1
DF.precip$precipitation <- b$.data
part, but runs fine outside of the function:
days=7
2003 Nov 19
5
ISOdate returns incorrect date?
Dear all,
I have found the following (for me) incomprehensible behaviour of
ISOdate (POSIXct):
> ISOdate(1900,6,16)
[1] "1900-06-15 14:00:00 Westeurop?ische Sommerzeit"
> ISOdate(1950,6,16)
[1] "1950-06-16 14:00:00 Westeurop?ische Sommerzeit"
Note that in the first case I get the 15th of June back, not the 16th as
I would have expected!
This happened under R-1.7.1 on
2003 Jul 26
1
bug plotting dates?
Hello R-experts!
I am using R Version 1.7.1 (2003-06-16) on a Debian Linux box and I
have discovered an odd result when plotting data involving dates. Please
try this minimal example:
a = seq(ISOdate(2000,1,1), ISOdate(2001,1,1), "months")
b = 1:13
plot(a,b, col="red")
What I get is a plot that looks as expected except the x-axis is mostly
red. Can anyone reproduce this
2002 May 28
2
histogramming dates
I'd like to make a plot showing frequency of an event. The data
is in a data from that includes Year, Month and Day (of month)
fields, so I created a Date with ISOdate(Year, Month, Day,
tz=''). I can plot frequencies for the year 2002 with
> thisyear <- Date[Year==2002]
> hist( thisyear, xaxt='n' )
> axis.POSIXct( 1, at=seq(min(thisyear), max(thisyear),
2009 Oct 06
1
ggplot2 applying a function based on facet
Look at the bottom of the message for my question
#here is a little function that I wrote
USGS <- function(input="discharge", days=7){
library(chron)
library(gsubfn)
#021973269 is the Waynesboro Gauge on the Savannah River Proper (SRS)
#02102908 is the Flat Creek Gauge (ftbrfcms)
#02133500 is the Drowning Creek (ftbrbmcm)
#02341800 is the Upatoi Creek Near Columbus (ftbn)
#02342500 is
2007 Mar 22
2
difftime / RBloomberg
hi,
I've troubles with some difftime objects. e.g.
ISOdate(2001, 4, 26) - ISOdate(2001, 2, 26) - 2
works, telling me "Time difference of 57 days". But when I'd like to add
days, such as
ISOdate(2001, 4, 26) - ISOdate(2001, 2, 26) + 2
the function gives me an error. Function "as.COMDate.chron" of the
Rbloomberg package doesn't work for that reason.
I'm
2009 Jul 16
6
Best way to replace :SS with :00
Not sure if there is an R way to do this or a regular express way, but here is what I am trying to do.
I've got lots of data where the format is HH:MM:SS, but I need to format it like HH:MM:00, i.e. round the second down to zero.
What is the best way to do this?
Thanks again.
Jason
2003 Apr 30
2
ylab in plot.POSIXct
I am using R-1.7.0 and have some data which consist of one vector of
numbers and a second corresponding vector of dates belonging to the
POSIXct class. I would like to plot the numbers against the dates.
What is the best way to do this?
It almost works to just call `plot.' However if I do this while using
the `ylab' parameter I get a warning message:
parameter "ylab"
2002 May 21
1
I() fails on objects of class POSIXct (PR#1587)
Although the documentation is somewhat sketchy, I() can be used to create
objects of class AsIs:
> I("a")
[1] "a"
attr(,"class")
[1] "AsIs" "character"
> I(4)
[1] 4
attr(,"class")
[1] "AsIs" "numeric"
> I(4 + 0i)
[1] 4+0i
attr(,"class")
[1] "AsIs" "complex"
>
This
2003 Sep 12
2
Sorting a vector by date
Hello out there....
Again I have a problem and I stuck...
How can I sort a vector of dates?
For example I have the vector
a<-ISOdate(2001, 1, 1) + 70*86400*runif(10)
How can this vector be sorted chronological?
And what's the function I should work with to handle these entries?
(in sense of: which(a>2001-01-04) or somehting like that)
Thank you for helping
M.Kirschbaum
2002 Apr 08
1
Problem(?) in strptime() -- short version
I decided my earlier email on this topic was rather long and wordy;
here's a condensed version.
I am sitting at a Solaris computer in the US/Pacific timezone.
I have a file of data having times that includes the following three values
2002-4-7 1:30:00 GMT
2002-4-7 2:30:00 GMT
2002-4-7 3:30:00 GMT
I have not been able to find a way to correctly convert these to
either of the POSIX
2018 Jan 22
0
Manipulating two large dataset differing by date and time
Hi Ogbos,
You can just use ISOdate. If you pass more values, it will process them:
ISOdate(2018,01,22)
[1] "2018-01-22 12:00:00 GMT"
> ISOdate(2018,01,22,18,17)
[1] "2018-01-22 18:17:00 GMT"
Add something like:
if(is.null(data$hour),data$hour<-12
then pass data$hour as it will default to the same value as if you
hadn't passed it.
Jim
On Mon, Jan 22, 2018 at 6:01
2004 Nov 03
3
cut POSIX results in NA - bug?
Dear all
I try to make hourly average by cut() function, which almost works
as *I* expected. What puzled me is that if there is only one item at
the end of your data it results in NA.
Example will explain what I mean
datum<-seq(ISOdate(2004,8,31), ISOdate(2004,9,1), "min")
cut(datum[1370:1381],"hour", labels=F)
[1] 1 1 1 1 1 1 1 1 1 1 1 NA
2002 Mar 08
1
1st January isn't (PR#1370)
In today's pre1.5.0
> ISOdate(2002,1,1)
[1] "2002-03-01 04:00:00 PST"
> ISOdate(2002,1,1)==ISOdate(2002,3,1)
[1] TRUE
It doesn't seem to happen for days other than 1/1
-thomas
> version
_
platform i686-pc-linux-gnu
arch i686
os linux-gnu
system i686, linux-gnu
status Under development (unstable)
major 1
minor 5.0
year 2002
month
2016 Apr 18
0
as.Date
The most important thing is that Date objects by definition do not include time of day. You want to look at ISOdatetime() and as.POSIXct() instead. And beware daylight savings time issues.
-pd
On 18 Apr 2016, at 15:09 , Ogbos Okike <giftedlife2014 at gmail.com> wrote:
> Dear All,
>
> I have a data set containing year, month, day and counts as shown below:
> data <-