Hi Ogbos,
Remember that there is an underlying numeric representation of dates.
as.Date assigns dates a number of days from an agreed origin
(1970-01-01) while POSIX dates assign a number of seconds. If you plot
in one system and then try to add points in another, it's not going to
work.
Jim
On S
Jim has pointed out the strptime function, but you can use as.POSIXct function
also... so
as.POSIXct( "2005-03-13 09:00:00" )
as.POSIXct( "03/13/2005 9:00", format="%m/%d/%Y %H:%M" )
or other variations should work.
On February 16, 2019 5:41:29 PM PST, Ogbos Okike
wrote:
>Dear Jeff,
>My erro
Dear Jeff,
My error please and sorry about that.
Not "1960-05-04 09:00:00".
I meant to write as.Date("2005-03-13"),-9,"b") and "2005-03-13 09:00:00".
My problem is the additional time factor.
I can text anywhere on my plot when dealing with /mm/dd but I can't
handle the new /mm/dd/hh/mm/
Hi Ogbos,
It may be easier to use strptime:
dta<-data.frame(year=rep(2005,5),month=rep("05",5),
day=c("01","06","11","16","21"),
hour=c(2,4,6,8,10),minute=rep(0,5),second=rep(0,5),value=1:5)
dta$Ptime<-strptime(paste(paste(dta$year,dta$month,dta$day,sep="-"),
paste(dta$hour,dta$minute,dta$secon
I have no idea how text(as.Date("2005-03-13"),-9,"b") would mark your plot
anywhere near 1960-05-04 09:00:00. Perhaps someone else does. Or perhaps you
can provide an actual minimal working example of what you had working before
you changed to POSIXct.
On February 16, 2019 1:08:38 PM PST, Ogbos
Dear Jeff,
One more problem please.
When I used as.Date(ISOdate(dta$year, dta$month, dta$day,dta$hour)) to
handle date, I could use text(as.Date("2005-03-13"),-9,"b") to label
my plot.
Now that I am using as.POSIXct(ISOdatetime(year,
month,day,hour,0,0))), can you please tell me how to text "b" o
Dear Jeff,
Please hold.
It is begging to work. There was an error somewhere. One ")" is
missing and as I went back to check the lines one by one with cursor,
I stubbed on non matching bracket.
I completed, run the code again and got some result.
Will get back to you once I am through.
Thanks in
Dear Jeff,
Thank you so much.
I ran the code but got an error message. I then try to run them line by line.
The problem is in:
dta$datetime <- with( dta, as.POSIXct(ISOdatetime(year, month,day,hour,0,0)))
Error in with(dta, as.POSIXct(ISOdatetime(year, month, day, hour, 0, 0))) :
object 'dta'
The Date class is not designed to handle time... you need to use the
ISOdatetime function and convert to POSIXct instead of Date. Just be sure to
set your timezone to some appropriate value before you convert any times into
datetime types.
Sys.setenv( TZ="GMT" )
# avoid using `data` as that is
9 matches
Mail list logo