0

I have a big data.frame and located some missing values respectively there are some wrong formats which I guess that strptime isn't able to detect:

D = data.frame(a = c("2007-06-22","2007-05-22","3032016"), b = c("2007-06-23","2007-06-24", "2007-06-25"))
           a          b
1 2007-06-22 2007-06-23
2 2007-05-22 2007-06-24
3    3032016 2007-06-25

How can I input a specific date-format into that cell? Something like:

D[3,1] <- "2016-03-30"

Edit: This question is indepdent of the initial format. Even for a set of:

           a          b
1 2007-06-22 2007-06-23
2 2007-05-22 2007-06-24
3        123 2007-06-25

or

           a          b
1 2007-06-22 2007-06-23
2 2007-05-22 2007-06-24
3         NA 2007-06-25

I would like to enter some new date-time data. It might be an easy question, nonetheless, I am not aware of the correct command.

Thanks.

Marco
  • 2,368
  • 6
  • 22
  • 48
  • I cannot see how my questions is a duplicate. There is no format description which fits my given data, i.d. I don't have a symbol of separation on 3032016. How can I apply it? – Marco Oct 27 '17 at 11:36
  • Perhaps the issue is just updating `D[3,1]`? it could be a problem with the dataframe defining the columns as factors instead of characters If it were characters your command would work. – Dave X Oct 31 '17 at 04:16
  • Try `D$a <- as.character(D$a)` or add the `stringsAsFactors=FALSE` option to your `data.frame()` command, then D[3,1] <- "2016-03-30"` and your assignment will work as I think you expect. – Dave X Oct 31 '17 at 04:23
  • Maybe improve the question by posting the error you get by typing the `D[3,1] <- "2016-03-30"` command & what you wanted to happen. – Dave X Oct 31 '17 at 04:27

0 Answers0