1

I am having troubles to separate large numbers into groups. For example:

a<-"2009031930111"

what I would like to get it:

year<-2009
month<-03
day<-19

Thank you in advance.

user3122260
  • 53
  • 1
  • 5

2 Answers2

3

Using substr() you can do:

a<-"2009031930111"
substr(a, 1, 4)
substr(a, 5, 6)
substr(a, 7, 8)

eventually you want to convert: as.numeric(substr(...))

jogo
  • 12,469
  • 11
  • 37
  • 42
3

As @Ananda Mahto said you can convert it into date object and then using lubridate package separate its years, months and date

a<-"2009031930111"
x <- strptime(a, "%Y%m%d")
library(lubridate)
year(x)
# [1] 2009
month(x)
# [1] 3
day(x)
# [1] 19
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213