Date object

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Date object

Veerappa Chetty
HI,
I have to work with data objects. I have trouble. I would like to convert
date to a integer of Julian dates omitting hours, minutes etc. I tried as.
Date and also as.POSIXlt, ct etc.

Please help me to compute the following difference. I get an "NA" for
output.

1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AM


Thanks.
Chetty
--
Professor of Family Medicine
Boston University
Tel: 617-414-6221, Fax:617-414-3345
emails: [hidden email],[hidden email]

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Date object

David Winsemius

On Apr 21, 2012, at 1:17 PM, Veerappa Chetty wrote:

> HI,
> I have to work with data objects. I have trouble. I would like to  
> convert
> date to a integer of Julian dates omitting hours, minutes etc. I  
> tried as.
> Date and also as.POSIXlt, ct etc.
>
> Please help me to compute the following difference. I get an "NA" for
> output.
>
> 1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AM

I didn't realize this until I started experimenting with your example,  
but there is no 0 hour that is recognized by strptime when using the  
am/pm time format:

 > strptime("1/14/2006 0:01:01 AM", format ="%m/%d/%Y %I:%M:%S %p")
[1] NA
 > strptime("1/14/2006 12:01:01 AM", format ="%m/%d/%Y %I:%M:%S %p")
[1] "2006-01-14 00:01:01"


If you want to offer a reproducible example of your data (not just  
console output we can do more with it.) I suggest you take you vector  
and offer the output of dput() on it.

--
David.

>
>
> Thanks.
> Chetty
> --
> Professor of Family Medicine
> Boston University
> Tel: 617-414-6221, Fax:617-414-3345
> emails: [hidden email],[hidden email]
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Date object

Rui Barradas
In reply to this post by Veerappa Chetty
Hello,

Veerappa Chetty wrote
HI,
I have to work with data objects. I have trouble. I would like to convert
date to a integer of Julian dates omitting hours, minutes etc. I tried as.
Date and also as.POSIXlt, ct etc.

Please help me to compute the following difference. I get an "NA" for
output.

1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AM


Thanks.
Chetty
--
Professor of Family Medicine
Boston University
Tel: 617-414-6221, Fax:617-414-3345
emails: [hidden email],[hidden email]

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Maybe this is system dependent, but with me, unlike what the help for 'strptime' says,
the format character 'H' can be used with the am/pm indicator even if  'p' is present.


> x <- c("1/14/2006 0:00:00 AM", "1/9/2006 0:00:00 AM")
> # With '%p' in format string
> d <- strptime(x, format ="%m/%d/%Y %H:%M:%S %p")
> d[1] - d[2]
Time difference of 5 days
> # Without '%p'
> d <- strptime(x, format ="%m/%d/%Y %H:%M:%S")
> d[1] - d[2]
Time difference of 5 days
>
> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Portuguese_Portugal.1252  LC_CTYPE=Portuguese_Portugal.1252  
[3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C                        
[5] LC_TIME=Portuguese_Portugal.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

loaded via a namespace (and not attached):
[1] tools_2.14.1

And the minus operator works as expected.

Hope this helps,

Rui Barradas
Reply | Threaded
Open this post in threaded view
|

Re: Date object

David Winsemius

On Apr 21, 2012, at 3:49 PM, Rui Barradas wrote:

> Hello,
>
>
> Veerappa Chetty wrote
>>
>> HI,
>> I have to work with data objects. I have trouble. I would like to  
>> convert
>> date to a integer of Julian dates omitting hours, minutes etc. I  
>> tried as.
>> Date and also as.POSIXlt, ct etc.
>>
>> Please help me to compute the following difference. I get an "NA" for
>> output.
>>
>> 1/14/2006 0:00:00 AM -1/9/2006 0:00:00 AM
>>
>>
>> Thanks.
>> Chetty
>> --
>> Professor of Family Medicine
>> Boston University
>> Tel: 617-414-6221, Fax:617-414-3345
>> emails: chettyvk@,vchetty@
>>
>> [[alternative HTML version deleted]]
>> f-contained, reproducible code.
>>
>
> Maybe this is system dependent, but with me, unlike what the help for
> 'strptime' says,
> the format character 'H' can be used with the am/pm indicator even  
> if  'p'
> is present.
>

It will not throw an error but it does ignore the am/pm indicator when  
%H is used.

 > x <- c("1/14/2006 12:00:00 AM", "1/9/2006 2:00:00 PM")
 > d <- strptime(x, format ="%m/%d/%Y %H:%M:%S %p")
 > d
[1] "2006-01-14 12:00:00" "2006-01-09 02:00:00"

--
David.


>
>> x <- c("1/14/2006 0:00:00 AM", "1/9/2006 0:00:00 AM")
>> # With '%p' in format string
>> d <- strptime(x, format ="%m/%d/%Y %H:%M:%S %p")
>> d[1] - d[2]
> Time difference of 5 days
>> # Without '%p'
>> d <- strptime(x, format ="%m/%d/%Y %H:%M:%S")
>> d[1] - d[2]
> Time difference of 5 days
>>
>> sessionInfo()
> R version 2.14.1 (2011-12-22)
> Platform: x86_64-pc-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=Portuguese_Portugal.1252  
> LC_CTYPE=Portuguese_Portugal.1252
> [3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C
> [5] LC_TIME=Portuguese_Portugal.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> loaded via a namespace (and not attached):
> [1] tools_2.14.1
>
> And the minus operator works as expected.
>
> Hope this helps,
>
> Rui Barradas
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Date-object-tp4576784p4577018.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.