Hi Ogbos, You can just use ISOdate. If you pass more values, it will process them:
ISOdate(2018,01,22) [1] "2018-01-22 12:00:00 GMT" > ISOdate(2018,01,22,18,17) [1] "2018-01-22 18:17:00 GMT" Add something like: if(is.null(data$hour),data$hour<-12 then pass data$hour as it will default to the same value as if you hadn't passed it. Jim On Mon, Jan 22, 2018 at 6:01 PM, Ogbos Okike <giftedlife2...@gmail.com> wrote: > Dear Members, > > Compliments of the Season!! > > > Below is a part of a code I use for Fourier analysis of signals. The code > handles data with the format 05 01 01 8628 (year, month, day and count) > 05 01 02 8589 (year, month, day and count) > The sample data is attached as 2005daily.txt. > > I would like to adapt the code to handle data of the form: > 05 01 01 00 4009 (year, month, day, hour and count) > 05 01 01 01 3969 (year, month, day, hour and count) > > The sample is also attached as 2005hourly.txt. > > Thank you very much for your kind inputs. > > Ogbos > > > > > data <- read.table("2005daily.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)) > x1 = data$date > y = data$counts > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.