Skip to content
Prev 314439 / 398503 Next

Question on creating Date variable

HI,

Just by taking David's solution:
?y <- as.POSIXct(paste( floor(x), round(60*(x-floor(x))) ), format="%H %M")
?y1<-data.frame(y,AM_PM=format(y,format="%p"))
?y1[3,1]-y1[4,1]
#Time difference of -40 mins
?y1[5,1]-y1[3,1]
#Time difference of -13 mins
?head(y1,2)
#??????????????????? y AM_PM
#1 2013-01-01 11:00:00??? AM
#2 2013-01-01 11:15:00??? AM
A.K.





----- Original Message -----
From: Christofer Bogaso <bogaso.christofer at gmail.com>
To: David Winsemius <dwinsemius at comcast.net>; David L Carlson <dcarlson at tamu.edu>
Cc: r-help at r-project.org
Sent: Tuesday, January 1, 2013 12:40 AM
Subject: Re: [R] Question on creating Date variable
On 01 January 2013 03:00:18, David Winsemius wrote:
'How could that represent any disclosure of proprietary information if 
presented with no context? ' I must agree with you. But I just dont 
want to take any risk! (job scenario in my country is not very 
optimistic and I want to give my boss minimal chance/reason to fire!)

And secondly with your approach, I cant do any calculation. Let take 
following example:

y <- format( as.POSIXct(as.character(x), format="%H.%M"),? # That is 
the input format
? ? ? ? ? ?  format="%I.%M %p")

y[3] - y[2]

This gives me following error:

Error in y[3] - y[2] : non-numeric argument to binary operator

I am having same error with Devid's approach as well:
Error in z[2] - z[1] : non-numeric argument to binary operator.

Thanks and regards,

______________________________________________
R-help at 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.