0

I am trying to split a date column of the format Y-M-D into three separate columns, e.g. I want to convert

0001-01-01

into

0001 01 01

It seems it should be straightforward to split by "-" but the strsplit function won't work as this is numeric data. Converting to character does not seem to work either. Would the grep function work here?

Sorry if this seems a straightforward question. I have trawled through similar problems for half an hour and can't find a simple solution here.

Many thanks.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
DJ-AFC
  • 569
  • 6
  • 16
  • 1
    I thought we agreed on using Google first in your previous question – David Arenburg Oct 14 '15 at 14:11
  • Hi David. As I stated in the question, I googled this problem for half an hour and tried out lots of the suggestions, but couldn't get them to work. This is actually my attempt to finish off what I wanted to do from the last post as I was afraid to ask anything further last time. My apologies for the persistent questions. – DJ-AFC Oct 14 '15 at 14:14
  • if the data is not a character, your first step should have been to convert it `strsplit(as.character(as.Date('0001-01-01')), '-')[[1]]` – rawr Oct 14 '15 at 14:25
  • DJ you should add sample data from your real data set for help. Or just read the linked question. – Pierre L Oct 14 '15 at 14:37

0 Answers0