I needed to turn character Date “2008-1-1” to numeric 20080101, but what I get is 200811, could anybody help me with this? Thank you very much. This is my code:
year <- c(2008:2012)
mth <- c(1:5)
day <- c(1:5)
A <- data.frame(cbind(year,mth,day))
date.ch <- as.character(with(A, paste(year, mth, day, sep="-")))
date.n <- as.numeric(with(A, paste(year, mth, day, sep="")))
You can use
as.numeric(format(as.Date(date.ch), '%Y%m%d'))