R中未使用的参数日期
unused argument date in R
当我尝试从日期对象中提取年份时出现奇怪的错误
这是我的约会日期:
structure(list(date = structure(c(15706, 15707, 15708, 15709,
15710, 15711), class = "Date")), .Names = "date", row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
当我通过管道传输到 lubridate::year(date)
时,出现以下错误。
Error in year(., date) : unused argument (date)
将您的对象命名为 data
,我假设这就是您所做的:
data %>%
year(date)
这对我也不起作用。你可以试试这个:
year(data$date)
在 pipe
中,如果您这样做,由于订单或评估的原因,它不会工作
dates %>%
lubridate::year(date)
Error in lubridate::year(., date) : unused argument (date)
要么我们需要pull
列然后应用函数
dates %>%
pull(date) %>%
lubridate::year(.)
或者另一种方法是使用 {}
中的函数
dates %>%
{lubridate::year(.$date)}
#[1] 2013 2013 2013 2013 2013 2013
或者使用 mutate
创建列的标准方法
dates %>%
mutate(year = lubridate::year(date))
或者,您可以使用 magrittr
运算符 %$%
:
library(magrittr)
dates %$%
year(date)
当我尝试从日期对象中提取年份时出现奇怪的错误
这是我的约会日期:
structure(list(date = structure(c(15706, 15707, 15708, 15709,
15710, 15711), class = "Date")), .Names = "date", row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
当我通过管道传输到 lubridate::year(date)
时,出现以下错误。
Error in year(., date) : unused argument (date)
将您的对象命名为 data
,我假设这就是您所做的:
data %>%
year(date)
这对我也不起作用。你可以试试这个:
year(data$date)
在 pipe
中,如果您这样做,由于订单或评估的原因,它不会工作
dates %>%
lubridate::year(date)
Error in lubridate::year(., date) : unused argument (date)
要么我们需要pull
列然后应用函数
dates %>%
pull(date) %>%
lubridate::year(.)
或者另一种方法是使用 {}
dates %>%
{lubridate::year(.$date)}
#[1] 2013 2013 2013 2013 2013 2013
或者使用 mutate
dates %>%
mutate(year = lubridate::year(date))
或者,您可以使用 magrittr
运算符 %$%
:
library(magrittr)
dates %$%
year(date)