dplyr row_number 等级错误 [英] dplyr row_number Error in rank
本文介绍了dplyr row_number 等级错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 dplyr 将 corr 列扩展到数据框中,但是 row_number 一直失败
I am trying to spread the corr column in a data frame wide using dplyr, but row_number keep failing with
> o<- out %>% group_by(site) %>% mutate(row = paste0("corr", row_number()))
Error in rank(x, ties.method = "first", na.last = "keep") :
argument "x" is missing, with no default
>dput(out)
structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("2001", "2002",
"2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010",
"2011", "2012", "2013", "2014", "2015", "2016", "2017", "2020",
"2021", "2022", "2102", "2107", "2108"), class = "factor"), corr = c(1,
0.96999258460714, 0.940002658241897, 0.912152752891952, 0.884318687047626,
0.857969509223287, 0.832630705318952, 0.807620983310881, 0.783158970946845,
1, 0.967337226340769, 0.930786616932812, 0.893007333276278, 0.855745958730318,
0.819162237318344, 0.784067927740006)), .Names = c("site", "corr"
), row.names = c(NA, 16L), class = "data.frame")
推荐答案
您在加载 dplyr
后加载了 plyr
.这会用 plyr::mutate
(在警告消息中说明)覆盖 dplyr::mutate
.要解决此问题,请先加载 plyr
,然后加载 dplyr
,或者在 mutate 调用中显式引用 dplyr
:
You have loaded plyr
after loading dplyr
. This overwrites dplyr::mutate
with plyr::mutate
(which is stated in a warning message). To remedy this issue, either load plyr
first and then load dplyr
, or explicitly reference dplyr
in the mutate call:
out %>% group_by(site) %>% dplyr::mutate(row = paste0("corr", row_number()))
这篇关于dplyr row_number 等级错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文