Split date into different columns for year, month and day

后端 未结 4 2055
醉话见心
醉话见心 2020-11-27 21:21

I have zoo objects that look like:

head(obs)

      Index pp
1932-01-01  0
1932-01-02  0.2
1932-01-03  0

and I want to split the ind

4条回答
  •  天涯浪人
    2020-11-27 21:42

    dtstr <- as.character( index(CET))
    
    CET$yr <- sapply(strsplit(dtstr, "-") , "[", 1)
    CET$mon <- sapply(strsplit(dtstr, "-") , "[", 2)
    CET$dt <- sapply(strsplit(dtstr, "-") , "[", 3)
    

提交回复
热议问题