我相信我如何将字符变为正确的格式(as.posixct)
感谢您的帮助。我是编码的新手,并且在将char施放到as.posixct方面遇到麻烦。 ## MyCode
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))))
错误来自Kaggle
Error in as.POSIXlt.character(x, tz, ...): character string is not in a standard unambiguous format
Traceback:
format(as.POSIXct(bike_rides$started_at), "%H")
as.POSIXct(bike_rides$started_at)
as.POSIXct.default(bike_rides$started_at)
as.POSIXct(as.POSIXlt(x, tz, ...), tz, ...)
as.POSIXlt(x, tz, ...)
as.POSIXlt.character(x, tz, ...)
stop("character string is not in a standard unambiguous format")
## DP的DF,
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"
)
我一直在各处寻找DF,但以某种方式在下面的代码堆中;
bike_rides$start_hour = format(as.POSIXct(bike_rides$started_at), "%H")
bike_rides$end_hour = format(as.POSIXct(bike_rides$ended_at), "%H")
不起作用,我无法找到更好的方法或语法来使该参数运行。
Thanks for the help. I am new to coding and having trouble with casting char to as.POSIXct.
##MYCode
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))))
Error from Kaggle
Error in as.POSIXlt.character(x, tz, ...): character string is not in a standard unambiguous format
Traceback:
format(as.POSIXct(bike_rides$started_at), "%H")
as.POSIXct(bike_rides$started_at)
as.POSIXct.default(bike_rides$started_at)
as.POSIXct(as.POSIXlt(x, tz, ...), tz, ...)
as.POSIXlt(x, tz, ...)
as.POSIXlt.character(x, tz, ...)
stop("character string is not in a standard unambiguous format")
##Dput for my DF
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 have been looking everywhere but somehow in the stack of code below;
bike_rides$start_hour = format(as.POSIXct(bike_rides$started_at), "%H")
bike_rides$end_hour = format(as.POSIXct(bike_rides$ended_at), "%H")
Does not work and I can not figure a better way or syntax to make that argument run.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)