r错误中的错误()`:!计算'年=年度(用户_ year)````''。由`as.posixlt.numeric()`::! ' rigins'必须提供
我知道这个问题已经很多次,但是由于某种原因,我仍然会遇到这个错误,尽管我应该根据这个论坛上的答案来起作用。也许我错过了一步。
基本上,我想将user_year
从num
更改为 date
,因此传单>传单
MAP LEGEND不显示一年使用逗号
。
示例数据(df
):
structure(list(USER_Date = structure(c(18996, 18633, 19011, 19012,
19016, 19019, 19020, 19011, 19023, 19023), class = "Date"), USER_Year = c(2022,
2021, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022), USER_Month = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1), USER_Day = c(4, 6, 19, 20, 24, 27,
28, 19, 31, 31)), sfc_columns = c("x", "y"), class = "data.frame", row.names = c(NA,
10L))
代码:
library(tidyverse)
# User lubridate
df = df %>% mutate(Year = year(USER_Year))
错误:
Error in `mutate()`:
! Problem while computing `Year = year(USER_Year)`.
Caused by error in `as.POSIXlt.numeric()`:
! 'origin' must be supplied
I know this question has been asked a lot of times but for some reason I still get this error even I though it should work based on the answers on this forum. Maybe I am missing a step.
Basically, I would like to change USER_Year
from num
to date
so the leaflet
map legend does not show the year with commas
.
Sample Data (df
):
structure(list(USER_Date = structure(c(18996, 18633, 19011, 19012,
19016, 19019, 19020, 19011, 19023, 19023), class = "Date"), USER_Year = c(2022,
2021, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022), USER_Month = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1), USER_Day = c(4, 6, 19, 20, 24, 27,
28, 19, 31, 31)), sfc_columns = c("x", "y"), class = "data.frame", row.names = c(NA,
10L))
Code:
library(tidyverse)
# User lubridate
df = df %>% mutate(Year = year(USER_Year))
Error:
Error in `mutate()`:
! Problem while computing `Year = year(USER_Year)`.
Caused by error in `as.POSIXlt.numeric()`:
! 'origin' must be supplied
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议改用年份转换为角色。这应该与传单一起使用。
输出
I'd recommend converting the year to character instead. This should work with leaflet.
Output
约会总是有一年,月和一天。因此,您将必须选择这样的随机日子:
或者更好,使用实际的月和日值:
然后使用
格式(DF $年,“%y”)
仅从“日期A date always has a year, month and day. So you will have to pick a random day like this:
or better, use the actual month and day values:
Then use
format(df$Year, "%Y")
to only get the year from the date