Re: [R] difftime in years

2016-08-04 Thread Jim Lemon
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

Re: [R] difftime in years

2016-08-04 Thread William Dunlap via R-help
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

[R] difftime in years

2016-08-04 Thread Thomas Subia via R-help
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

Re: [R] difftime() out by 1 hour

2013-02-01 Thread PIKAL Petr
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) >

Re: [R] difftime() out by 1 hour

2013-02-01 Thread Pascal Oettli
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

[R] difftime() out by 1 hour

2013-02-01 Thread Boots
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

Re: [R] difftime producing NA values in R 2.12.2

2011-10-25 Thread Jeff Newmiller
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

Re: [R] difftime producing NA values in R 2.12.2

2011-10-25 Thread Richard M. Heiberger
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

Re: [R] difftime producing NA values in R 2.12.2

2011-10-25 Thread Adrienne Wootten
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

Re: [R] difftime producing NA values in R 2.12.2

2011-10-25 Thread Ben Bolker
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] difftime producing NA values in R 2.12.2

2011-10-25 Thread Adrienne Wootten
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

Re: [R] difftime on vector

2011-09-15 Thread jim holtman
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

[R] difftime on vector

2011-09-15 Thread bradford
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

Re: [R] difftime error

2010-10-25 Thread dpender
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@

Re: [R] difftime error

2010-10-25 Thread Prof Brian Ripley
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

Re: [R] difftime error

2010-10-25 Thread Uwe Ligges
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] difftime error

2010-10-25 Thread dpender
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

[R] difftime problems with daylight saving time?

2010-09-15 Thread ravi
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

Re: [R] difftime result for days not an integer?

2010-02-11 Thread Don MacQueen
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

Re: [R] difftime result for days not an integer?

2010-02-11 Thread Thomas Lumley
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

Re: [R] difftime result for days not an integer?

2010-02-11 Thread Barry Rowlingson
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

[R] difftime result for days not an integer?

2010-02-11 Thread Jonathan
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:/

Re: [R] difftime

2008-12-09 Thread Gabor Grothendieck
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

Re: [R] difftime

2008-12-09 Thread Prof Brian Ripley
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

Re: [R] difftime

2008-12-09 Thread Henrique Dallazuanna
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

[R] difftime

2008-12-09 Thread eric lee
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

Re: [R] difftime result in years?

2008-04-22 Thread Gabor Grothendieck
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/

[R] difftime result in years?

2008-04-22 Thread Worik R
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]]