Jamar Wilson
Jamar Wilson

Reputation: 11

Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format (Help)

Want to first thank the community for your help. I am new to R and this is my first post. As mentioned earlier, I am receiving a error as I am trying to run my R markdown or in Kaggle notebook..

bike_rides$month <- format(as.Date(bike_rides$date), "%m")
bike_rides$day <- format(as.Date(bike_rides$date), "%d")
bike_rides$year <- format(as.Date(bike_rides$date), "%y")
bike_rides$weekday <- format(as.Date(bike_rides$date), "%a")
bike_rides$start_hour = format(as.POSIXct(bike_rides$started_at), "%H")
bike_rides$end_hour = format(as.POSIXct(bike_rides$ended_at), "%H")
bike_rides$season <- ifelse (bike_rides$month %in% c('06','07','08'), "Summer",
                         ifelse (bike_rides$month %in% c('09','10','11'), "Fall",
                                 ifelse (bike_rides$month %in% c('12','01','02'), "Winter",
                                         ifelse (bike_rides$month %in% c('03','04','05'), "Spring", NA))))

I am getting this error from Kaggle:

Error in as.POSIXlt.character(x, tz, ...): character string is not in a standard unambiguous format

Traceback:

  1. format(as.POSIXct(bike_rides$started_at), "%H")
  2. as.POSIXct(bike_rides$started_at)
  3. as.POSIXct.default(bike_rides$started_at)
  4. as.POSIXct(as.POSIXlt(x, tz, ...), tz, ...)
  5. as.POSIXlt(x, tz, ...)
  6. as.POSIXlt.character(x, tz, ...)
  7. stop("character string is not in a standard unambiguous format")

####Dput

    bike_rides <-
  structure(
    list(
      ride_id = c("A847FADBBC638E45", "5405B80E996FF60D",
                  "5DD24A79A4E006F4"),
      rideable_type = c("docked_bike", "docked_bike",
                        "docked_bike"),
      started_at = structure(
        c(1587923114, 1587143334,
          1585763653),
        class = c("POSIXct", "POSIXt"),
        tzone = "UTC"
      ),
      ended_at = structure(
        c(1587924723, 1587143823, 1585764516),
        class = c("POSIXct", "POSIXt"),
        tzone = "UTC"
      ),
      start_station_name = c("Eckhart Park",
                             "Drake Ave & Fullerton Ave", "McClurg Ct & Erie St"),
      start_station_id = c("86",
                           "503", "142"),
      end_station_name = c(
        "Lincoln Ave & Diversey Pkwy",
        "Kosciuszko Park",
        "Indiana Ave & Roosevelt Rd"
      ),
      end_station_id = c("152",
                         "499", "255"),
      start_lat = c(41.8964, 41.9244, 41.8945),
      start_lng = c(-87.661,-87.7154,-87.6179),
      end_lat = c(41.9322,
                  41.9306, 41.8679),
      end_lng = c(-87.6586,-87.7238,-87.623),
      member_casual = c("member", "member", "member"),
      date = structure(c(18378,
                         18369, 18353), class = "Date"),
      month = c("04", "04", "04"),
      day = c("26", "17", "01"),
      year = c("20", "20", "20"),
      weekday = c("Sun", "Fri", "Wed"),
      start_hour = c("17", "17",
                     "17"),
      end_hour = c("18", "17", "18"),
      season = c("Spring",
                 "Spring", "Spring")
    ),
    row.names = c(NA, 3L),
    class = "data.frame"
  )

I do understand that I somehow have to maybe change the class start_hour from chr to date, but I have no clue how to do so as the code before it works fine.

Any help would due.. thanks

Upvotes: 0

Views: 482

Answers (0)

Related Questions