[R] Extending my code

Ogbos Okike g||ted|||e2014 @end|ng |rom gm@||@com
Fri Feb 15 08:25:11 CET 2019


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 a hurry.
Best regards
Ogbos


On Fri, Feb 15, 2019 at 8:15 AM Ogbos Okike <giftedlife2014 using gmail.com> wrote:
>
> 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' not found
>
> Thanks for another time.
> Best
> Ogbos
>
> On Fri, Feb 15, 2019 at 7:51 AM Jeff Newmiller <jdnewmil using dcn.davis.ca.us> wrote:
> >
> > 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 the name of a base R function
> > dta <- read.table("CALG.txt", col.names = c("year", "month", "day", "hour", "counts"))
> > dta$year <- with( dta, ifelse(year < 50, year + 2000, year + 1900)
> > dta$datetime <- with( dta, as.POSIXct(ISOdatetime(year, month,day,hour,0,0)))
> >
> > I don't see why you feel obliged to copy the timestamp out of the data frame into x, but that is your business.
> >
> > Appropriate timezone values can be reviewed with the OlsonNames() function.
> >
> >
> > On February 14, 2019 10:29:58 PM PST, Ogbos Okike <giftedlife2014 using gmail.com> wrote:
> > >Dear List,
> > >I have a simple code with which I convert year, month, and day to a
> > >date format.
> > >My data looks like:
> > >67 01 26    18464
> > >67 01 26    18472
> > >67 01 26    18408
> > >67 01 26    18360
> > >67 01 26    18328
> > >67 01 26    18320
> > >67 01 26    18296
> > >
> > >while my code is:
> > >
> > >
> > >data <- read.table("CALG.txt", col.names = c("year", "month", "day",
> > >"counts"))
> > > new.century <- data$year < 50
> > >data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
> > >data$date <- as.Date(ISOdate(data$year, data$month, data$day))
> > >x = data$date
> > > y = data$counts
> > >
> > >I now wish to extend this code to be able to include hour for another
> > >data of the format:
> > >05 01 01 00    4009
> > >05 01 01 01    3969
> > >05 01 01 02    3946
> > >05 01 01 03    3975
> > >05 01 01 04    3960
> > >05 01 01 05    3974
> > >05 01 01 06    3971
> > >05 01 01 07    3970
> > >That is, I now would like to include hour in:
> > >data <- read.table("CALG.txt", col.names = c("year", "month", "day",
> > >"counts")).
> > >
> > >I am aware there are many other way of conversion but I have a
> > >specific interest here. This code is a preamble to a larger code and
> > >changing it to another format other than what I have will not be
> > >compatible with the general code. Or will rather be difficult for me
> > >to get another format fit into my main code.
> > >
> > >So if you would be kind enough to assist me to run the read.table in
> > >the format:
> > >
> > >data <- read.table("CALG.txt", col.names = c("year", "month",
> > >"day","hour", "counts"))
> > >
> > >and then run the rest as:
> > >
> > >new.century <- data$year < 50
> > >data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
> > >data$date <- as.Date(ISOdate(data$year, data$month,
> > >data$day,data$hour))
> > >x = data$date
> > >
> > >such that year, month, day and hour will be stored in x,
> > >
> > >I will be very thankful.
> > >
> > >Thank you so much for your kind assistance.
> > >Best regards
> > >Ogbos
> > >
> > >______________________________________________
> > >R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > >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.
> >
> > --
> > Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list