-2

enter image description here

I have dataset in this format 1/2/2015 9:43

I am not sure why the code below showing me warnings.

in_time <- sapply(in_time, function(x) as.POSIXlt(x, origin="1-2-2015","%d-%m-%Y %H:%M"))

There were 50 or more warnings (use warnings() to see the first 50)

The errors are:

In as.POSIXct.POSIXlt(x) : unknown timezone '%d/%m/%Y %H:%M'

kath
  • 7,624
  • 17
  • 32
  • 1
    What warnings did you get? Have you tried `warnings()`? Please provide a [minimal, reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) – kath Aug 21 '18 at 11:29
  • 1
    Well to start, you specify `format = "%d-%m-%Y %H:%M"` yet you say your dataset has format `1/2/2015 9:43`. This works just fine `as.POSIXlt("1/2/2015 9:43", origin = "1-2-2015", format = "%d/%m/%Y %H:%M")` – Maurits Evers Aug 21 '18 at 11:31
  • @Mauritis in_time <- sapply(in_time, function(x) as.POSIXlt(x, origin="1-2-2015","%d/%m/%Y %H:%M")) There were 50 or more warnings (use warnings() to see the first 50) – wyne thomas Aug 21 '18 at 11:36
  • Please edit your question, when you provide new information. – kath Aug 21 '18 at 11:37
  • @wynethomas You should include some minimal sample data (i.e. some date entries that are representative of your data); as I say in my comment above, if I fix the `format` I don't get any warnings, so your problem is either a simple typo and/or not reproducible. – Maurits Evers Aug 21 '18 at 11:39
  • @wynethomas You need to take a look at the link kath provides in her first comment. Please make your example reproducible! Include sample data! – Maurits Evers Aug 21 '18 at 11:43
  • @MauritsEvers Included sample dataset as image in the question – wyne thomas Aug 21 '18 at 11:45
  • 2
    Please provide your data in a reproducible format. See the link in my first comment. Use for example `dput()` – kath Aug 21 '18 at 11:47
  • `lapply` gives better results than `sapply`. – Rui Barradas Aug 21 '18 at 12:09

1 Answers1

0

One possibility is that as.POSIXlt isn't able to determine your system's time zone, e.g. if Sys.timezone() is returning NA.

You can specify a timezone manually using the tz argument, e.g.:

in_time <- sapply(in_time, function(x) {
    as.POSIXlt(x, origin="1-2-2015","%d-%m-%Y %H:%M", tz = "Europe/London")
})

A list of valid time zones you can supply to tz can be found using the OlsonNames() function (see also help("time zones")).

Scott Ritchie
  • 10,293
  • 3
  • 28
  • 64