Hi Thomas,
Be aware that if you are attempting to calculate "birthday age", it is
probably better to do it like this:
bdage<-function(dob,now) {
dobbits<-as.numeric(unlist(strsplit(dob,"/")))
nowbits<-as.numeric(unlist(strsplit(now,"/")))
return(nowbits[3]-dobbits[3]-
(nowbits[2] wrote:
> dif
difftime objects do not accept 'years' as a value for 'units', so you have
to change it to numeric.
as.numeric(age_days, units="days") / 365.242
The units="days" is not needed since you specified it in the call
to difftime, but it needs to be in one of those places.
Bill Dunlap
TIBCO Softwar
Colleagues,
age_days <- difftime(Date,DOM,units="days")
date_vals$age_yrs <- age_days/365.242
I'm trying to calculate the number of years between DOM and Date.
The output reads
DOM Date age_yrs
1 2005-04-04 2015-05-13 10.10563 days
How doe
day, February 01, 2013 9:18 AM
> To: Boots
> Cc: R Help
> Subject: Re: [R] difftime() out by 1 hour
>
> Hello,
>
> Here is the result I get using your script:
>
> > sessionInfo()
> R version 2.15.2 (2012-10-26)
> Platform: x86_64-suse-linux-gnu (64-bit)
>
Hello,
Here is the result I get using your script:
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-suse-linux-gnu (64-bit)
[1] "2012-03-31 21:00:00" "2012-04-01 00:00:00" "2012-04-01 03:00:00"
[4] "2012-04-01 06:00:00"
Time differences in hours
[1] 3 3 3
attr(,"tzone")
[1] ""
[1
I have a problem with results from difftime being 1 hour different than
expected. 2 examples are given below:
datetime <- matrix(data=rbind(c("2012-03-31 21:00:00", "2012-04-01 00:00:00",
"2012-04-01 03:00:00", "2012-04-01 06:00:00"),
c("2012-10-06 21:00:00", "2012-10-07 00:0
This is daylight savings time issue.
Use chron or set your TZ environment variable to a standard-time-only timezone
(or don't enter nonexistent time values for the timezone in which you wish to
compute).
---
Jeff Newmiller Th
I would like to nominate this for a new item in the FAQ for R.
The FAQ should mention both the daylight-savings-time switch
and have a reference to the R-News article
Rich
On Tue, Oct 25, 2011 at 3:16 PM, Adrienne Wootten wrote:
> Ben,
>
> Thanks! That really helped. Turns out all the data bei
Ben,
Thanks! That really helped. Turns out all the data being used was in
EST and currently the system timezone is EDT. Thanks for the tip!
A
On Tue, Oct 25, 2011 at 2:27 PM, Ben Bolker wrote:
> Adrienne Wootten ncsu.edu> writes:
>
>>
>> R-listers,
>>
>> I have noticed several posts on issue
Adrienne Wootten ncsu.edu> writes:
>
> R-listers,
>
> I have noticed several posts on issues with difftime producing NA's
> but they have been for older versions of R. Here's the issue
> associated with difftime that I am dealing with in R 2.12.2.
>
>
> > difftime(strptime("03/11/2007 02:00"
R-listers,
I have noticed several posts on issues with difftime producing NA's
but they have been for older versions of R. Here's the issue
associated with difftime that I am dealing with in R 2.12.2.
> preciptime = strptime("01/10/2007 14:00",format="%m/%d/%Y %H:%M")
> class(preciptime)
[1] "PO
You need to supply two vectors:
> x <- seq(Sys.time(), by = '10 min', length = 10)
> x
[1] "2011-09-15 09:58:30 EDT" "2011-09-15 10:08:30 EDT" "2011-09-15
10:18:30 EDT"
[4] "2011-09-15 10:28:30 EDT" "2011-09-15 10:38:30 EDT" "2011-09-15
10:48:30 EDT"
[7] "2011-09-15 10:58:30 EDT" "2011-09-15 11
How can I apply difftime to a vector of sorted dates? I can do this just
fine with diff, but difftime doesn't seem to take in a vector.
> diff(r$BOOKING_DATE)
Works. Great!
> difftime(r$MY_DATE, units="days")
Error in as.POSIXct(time2) : argument "time2" is missing, with no default
Thanks,
Bra
That's it exactly. Do you know how to specify the timezone for Sydney,
Australia?
--
View this message in context:
http://r.789695.n4.nabble.com/difftime-error-tp3010105p3010175.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@
On Mon, 25 Oct 2010, dpender wrote:
R community,
I am trying to create an array of the time differences between datapoints
for a very large set. For some reason for 4 of the values the difference
has been calculated as NA.
Looking at the individual points two of them are "1981-03-29 01:40:00
On 25.10.2010 12:55, dpender wrote:
R community,
I am trying to create an array of the time differences between datapoints
for a very large set. For some reason for 4 of the values the difference
has been calculated as NA.
Looking at the individual points two of them are "1981-03-29 01:40:0
R community,
I am trying to create an array of the time differences between datapoints
for a very large set. For some reason for 4 of the values the difference
has been calculated as NA.
Looking at the individual points two of them are "1981-03-29 01:40:00" and
"1981-03-29 02:00:00"
This is th
Hi,
I seem to be having problems in calculating the period between two times, one
with and the other without daylight saving time. Consider the following command
:
> as.numeric(difftime(as.POSIXct("2010-04-01 06:00:00
>CEST"),as.POSIXct("2010-03-03 08:27:00 CET"),units="hours"))
[1] 692.55
No
Which brings up another point.
The help page for difftime specifies that it operates on date-time or
date objects. But
'2004-08-05' is neither of these, it is a character object.
At this point, one might ask... I didn't give it what it asked for,
what is it going to do?
(might give me an er
On Thu, 11 Feb 2010, Jonathan wrote:
Anybody have an idea why I would get a non-integer value for the
number of days here?
difftime('2004-08-05','2001-01-03',units='days')
Time difference of 1309.958 days
Because it's not a whole number of 24-hour periods, due to daylight saving
time: 0.95
On Thu, Feb 11, 2010 at 8:40 PM, Jonathan wrote:
> Anybody have an idea why I would get a non-integer value for the
> number of days here?
>
>> difftime('2004-08-05','2001-01-03',units='days')
> Time difference of 1309.958 days
>
>
> Would you just round off?
It's one hour short of an integer num
Anybody have an idea why I would get a non-integer value for the
number of days here?
> difftime('2004-08-05','2001-01-03',units='days')
Time difference of 1309.958 days
Would you just round off?
Best,
Jon
__
R-help@r-project.org mailing list
https:/
I guess its the same problem as this (run after your
code):
> as.POSIXct(a, tz = "")
[1] NA
> as.POSIXct(b, tz = "")
[1] NA
> difftime(b, a, units="days")
Time difference of NA days
If you explicitly specify the tz as "GMT" then it works as expected:
> as.POSIXct(a, tz = "GMT")
[1] "1999-10-08 0
In the absence of any of the information requested in the posting guide,
all we can say is that this works for other people (e.g. on both Mac OS X
and Fedora 8 for me).
Apart from the usual info, we would need to know your timezone.
On Tue, 9 Dec 2008, eric lee wrote:
Hi. I'm trying to take
Perhaps you are getting warning messages from difftime like this:
"Warning messages:
1: In structure(.Internal(as.POSIXct(x, tz)), class = c("POSIXt",
"POSIXct"), :
unable to identify current timezone 'V':
please set environment variable 'TZ'
2: In structure(.Internal(as.POSIXct(x, tz)), class
Hi. I'm trying to take the difference in days between two times. Can
you point out what's wrong, or suggest a different function? When I
try the following code, The following code works fine:
a <- strptime(1911100807,format="%Y%m%d%H",tz="GMT")
b <- strptime(1911102718,format="%Y%m%d%H",tz="GM
Try this:
fmt <- "%d/%m/%Y"
d1 <- as.Date("20/11/1962", fmt)
d2 <- as.Date("20/5/1964", fmt)
julian(d2, d1)/365.25
On Tue, Apr 22, 2008 at 8:25 PM, Worik R <[EMAIL PROTECTED]> wrote:
> I would like to know how many years (including partial years) are between
> two dates.
>
> So difftime("20/11/
I would like to know how many years (including partial years) are between
two dates.
So difftime("20/11/1962", "20/5/1964", units="years") would be about 1.5
But units of years are not available.
cheers
Worik
[[alternative HTML version deleted]]
28 matches
Mail list logo