[R] Extending my code

Ogbos Okike g||ted|||e2014 @end|ng |rom gm@||@com
Fri Feb 15 07:29:58 CET 2019


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



More information about the R-help mailing list