[R] time conversion from second to Y M D H M S format

2012-02-02 Thread uday

I have some time data and which is in seconds 

time -c( 126230400 126252000 126273600 126295200 126316800 126338400)
now I wanted to convert this time to Y M D H M S format

I have tried following codes but it does not give me the  out put in  Y M D
H M S

time_t1 - as.POSIXlt(time, origin=2005-01-01, tz=GMT) 
 
time_f - as.POSIXct(time, origin=2005-01-01, tz=GMT)

So somebody could please tell me how to fix this problem. 

Thanks  





--
View this message in context: 
http://r.789695.n4.nabble.com/time-conversion-from-second-to-Y-M-D-H-M-S-format-tp4350831p4350831.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] time conversion from second to Y M D H M S format

2012-02-02 Thread uday
Dear Uwe ,
Thanks for reply 
I have tried format function that u suggested (format(time_t1, %Y %m %d %H
%M %S)  and I got 
format(time_t1, %Y %m %d %H %M %S) 
[1] 126230400 126252000 126273600 126295200 126316800 126338400


I think something  is not working correct.





--
View this message in context: 
http://r.789695.n4.nabble.com/time-conversion-from-second-to-Y-M-D-H-M-S-format-tp4350831p4352062.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] time conversion from second to Y M D H M S format

2012-02-02 Thread R. Michael Weylandt
It works for me as well so there's something funny on your end: please
run the following *verbatim* (in a vanilla R session):

sink(ForRHelp.txt)
print(sessionInfo())
cat(\n)
print(.Platform)
time -as.POSIXct(c( 126230400, 126252000, 126273600),
origin=2005-01-01, tz=GMT)
print(time)
cat(format(time[1], %Y %m %d %H %M %S), \n)
cat(format(time[2], %Y %m %d %H %M %S), \n)
cat(format(time[3], %Y %m %d %H %M %S), \n)
sink()
print(paste(Text file in, getwd()))

and send the resulting txt file to the list (so we can see exactly
your system config and what not).

Michael


On Thu, Feb 2, 2012 at 11:57 AM, uday uday_143...@hotmail.com wrote:
 Dear Uwe ,
 Thanks for reply
 I have tried format function that u suggested (format(time_t1, %Y %m %d %H
 %M %S)  and I got
 format(time_t1, %Y %m %d %H %M %S)
 [1] 126230400 126252000 126273600 126295200 126316800 126338400


 I think something  is not working correct.





 --
 View this message in context: 
 http://r.789695.n4.nabble.com/time-conversion-from-second-to-Y-M-D-H-M-S-format-tp4350831p4352062.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org 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.

__
R-help@r-project.org 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.


Re: [R] time conversion from second to Y M D H M S format

2012-02-02 Thread Berend Hasselman

On 02-02-2012, at 19:23, R. Michael Weylandt wrote:

 It works for me as well so there's something funny on your end: please
 run the following *verbatim* (in a vanilla R session):
 
 sink(ForRHelp.txt)
 print(sessionInfo())
 cat(\n)
 print(.Platform)
 time -as.POSIXct(c( 126230400, 126252000, 126273600),
 origin=2005-01-01, tz=GMT)
 print(time)
 cat(format(time[1], %Y %m %d %H %M %S), \n)
 cat(format(time[2], %Y %m %d %H %M %S), \n)
 cat(format(time[3], %Y %m %d %H %M %S), \n)
 sink()
 print(paste(Text file in, getwd()))
 
 and send the resulting txt file to the list (so we can see exactly
 your system config and what not).
 
 Michael

I appear to have the same or similar problem on Mac OS X 10.6.8
I ran the above script with R --vanilla.
The result is

R version 2.14.1 Patched (2012-01-30 r58238)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_GB/en_GB/en_GB/C/en_GB/en_GB

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

$OS.type
[1] unix

$file.sep
[1] /

$dynlib.ext
[1] .so

$GUI
[1] X11

$endian
[1] little

$pkgType
[1] mac.binary.leopard

$path.sep
[1] :

$r_arch
[1] x86_64

[1] 2009-01-01 00:00:00 GMT 2009-01-01 06:00:00 GMT
[3] 2009-01-01 12:00:00 GMT
2009 01 01 00 00 00 
2009 01 01 06 00 00 
2009 01 01 12 00 00 


Berend

__
R-help@r-project.org 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.


Re: [R] time conversion from second to Y M D H M S format

2012-02-02 Thread Berend Hasselman

On 02-02-2012, at 21:10, Berend Hasselman wrote:

 
 On 02-02-2012, at 19:23, R. Michael Weylandt wrote:
 
 It works for me as well so there's something funny on your end: please
 run the following *verbatim* (in a vanilla R session):
 
 sink(ForRHelp.txt)
 print(sessionInfo())
 cat(\n)
 print(.Platform)
 time -as.POSIXct(c( 126230400, 126252000, 126273600),
 origin=2005-01-01, tz=GMT)
 print(time)
 cat(format(time[1], %Y %m %d %H %M %S), \n)
 cat(format(time[2], %Y %m %d %H %M %S), \n)
 cat(format(time[3], %Y %m %d %H %M %S), \n)
 sink()
 print(paste(Text file in, getwd()))
 
 and send the resulting txt file to the list (so we can see exactly
 your system config and what not).
 
 Michael
 
 I appear to have the same or similar problem on Mac OS X 10.6.8
 I ran the above script with R --vanilla.
 The result is
 
 R version 2.14.1 Patched (2012-01-30 r58238)
 Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
 
 locale:
 [1] en_GB/en_GB/en_GB/C/en_GB/en_GB
 
 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base 
 
 $OS.type
 [1] unix
 
 $file.sep
 [1] /
 
 $dynlib.ext
 [1] .so
 
 $GUI
 [1] X11
 
 $endian
 [1] little
 
 $pkgType
 [1] mac.binary.leopard
 
 $path.sep
 [1] :
 
 $r_arch
 [1] x86_64
 
 [1] 2009-01-01 00:00:00 GMT 2009-01-01 06:00:00 GMT
 [3] 2009-01-01 12:00:00 GMT
 2009 01 01 00 00 00 
 2009 01 01 06 00 00 
 2009 01 01 12 00 00 


Disregard my previous posting.
Results are correct.

Berend

__
R-help@r-project.org 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.


Re: [R] time conversion from second to Y M D H M S format

2012-02-02 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of uday
 Sent: Thursday, February 02, 2012 8:57 AM
 To: r-help@r-project.org
 Subject: Re: [R] time conversion from second to Y M D H M S format
 
 Dear Uwe ,
 Thanks for reply
 I have tried format function that u suggested (format(time_t1, %Y %m
 %d %H
 %M %S)  and I got
 format(time_t1, %Y %m %d %H %M %S)
 [1] 126230400 126252000 126273600 126295200 126316800
 126338400
 
 
 I think something  is not working correct.
 
 

You are right something is not working correctly.  But you haven't shown what 
you did from beginning to end, so we don't know what that something might be.  
Try this

 time -c( 126230400, 126252000, 126273600, 126295200, 126316800, 126338400)
 time_t1- as.POSIXlt(time, origin=2005-01-01, tz=GMT)
 time_t1
[1] 2009-01-01 00:00:00 GMT 2009-01-01 06:00:00 GMT
[3] 2009-01-01 12:00:00 GMT 2009-01-01 18:00:00 GMT
[5] 2009-01-02 00:00:00 GMT 2009-01-02 06:00:00 GMT
 format(time_t1, %Y %m %d %H %M %S)
[1] 2009 01 01 00 00 00 2009 01 01 06 00 00 2009 01 01 12 00 00
[4] 2009 01 01 18 00 00 2009 01 02 00 00 00 2009 01 02 06 00 00


Does that not do what you wanted?

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


__
R-help@r-project.org 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.


[R] Time conversion

2008-10-02 Thread Michael Pearmain
I'm trying to convert a variable that is imported from CSV into a datetime,I'm
trying to use the strptime function but with no joy, can anyone offer any
advise?

i have a vector
timestamp
07-07-2008-21:03:55
07-07-2008-19:52:55
07-07-2008-19:54:14
07-07-2008-15:24:01
07-07-2008-13:39:17
07-07-2008-13:39:55


timestamp-strptime(timestamp,%d-%m-%y-%H:%M:%S)
## then filter on the datetime
time-ifelse(timestamp 07-08-2008-00:00:00, TRUE, FALSE)



-- 
Michael Pearmain
Senior Statistical Analyst


Google UK Ltd
Belgrave House
76 Buckingham Palace Road
London SW1W 9TQ
United Kingdom
t +44 (0) 2032191684
[EMAIL PROTECTED]

If you received this communication by mistake, please don't forward it to
anyone else (it may contain confidential or privileged information), please
erase all copies of it, including all attachments, and please let the sender
know it went to the wrong person. Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


Re: [R] Time conversion

2008-10-02 Thread Richard . Cotton
 I'm trying to convert a variable that is imported from CSV into a 
datetime,I'm
 trying to use the strptime function but with no joy, can anyone offer 
any
 advise?
 
 i have a vector
 timestamp
 07-07-2008-21:03:55
 07-07-2008-19:52:55
 07-07-2008-19:54:14
 07-07-2008-15:24:01
 07-07-2008-13:39:17
 07-07-2008-13:39:55
 
 
 timestamp-strptime(timestamp,%d-%m-%y-%H:%M:%S)
 ## then filter on the datetime
 time-ifelse(timestamp 07-08-2008-00:00:00, TRUE, FALSE)

1. Since the years are of the form , your format vector should be 
%d-%m-%Y-%H:%M:%S.

2. You don't need the ifelse call if you the last two arguments are just 
TRUE, FALSE

3. You do need to call strptime on your comparision date.

timestamp - c(07-07-2008-21:03:55,
   07-07-2008-19:52:55,
   07-07-2008-19:54:14,
   07-07-2008-15:24:01,
   07-07-2008-13:39:17,
   07-07-2008-13:39:55)
timestamp - strptime(timestamp,%d-%m-%Y-%H:%M:%S)
time - timestamp  strptime(07-08-2008-00:00:00,%d-%m-%Y-%H:%M:%S)

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

__
R-help@r-project.org 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.