[Solved] Drop part of an integer in R [duplicate]


Your expected output seem to be a string, I would suggest you will stay in the integer world for efficiency and convenience, something like (the idea’s taken from here)

((dataset / 100) %% 1) * 100 
## [1]  1  2  3  4  5  6  7  8  9 10 11 12
## OR just `dataset - 201600` ?

You could also easily achieve this using substring (if you want a character vector in return)

substring(dataset, 5)
# [1] "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12"

Or you could do a date manipulation

as.POSIXlt(paste0(as.character(dataset), "01"), format = "%Y%m%d")$mon + 1L
# [1]  1  2  3  4  5  6  7  8  9 10 11 12

solved Drop part of an integer in R [duplicate]