I am trying to split one column into three columns so I can give a date format. Currently the data set looks like this
YYYYMMDD Number
20020101 0.21
20020102 0.34
20020103 1.22
I want it to look like this
Year Month Day Number
2002 01 01 0.21
2002 01 02 0.34
2002 01 03 1.22
I have the following code written and it works in the sense that i can split up the column, but in doing so I create new data frames and I am unsure how to then add back in the data.frame to the original data.set
- dataset=data
Is there a nicer way to do it? or how to do I get new2 + new to combine with data?
res <- strsplit(data$YYYYMMDD, "(?<=.{4})" , perl = TRUE)
new<-do.call(rbind, res)
summary(new)
colnames(new)<-c("Year", "MMDD")
new<-as.data.frame(new)
new$MMDD<-as.character(new$MMDD)
res <- strsplit(new$MMDD, "(?<=.{2})" , perl = TRUE)
new2<-do.call(rbind, res)
summary(new2)
colnames(new2)<-c("Month", "Dom")
new2<-as.data.frame(new2)