gpt4 book ai didi

r - dplyr row_number排名错误

转载 作者:行者123 更新时间:2023-12-04 11:09:45 31 4
gpt4 key购买 nike

我正在尝试使用dplyr在整个数据帧中分布corr列,但是row_number继续失败

> 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")

最佳答案

加载plyr之后,您已经加载了dplyr。这将用dplyr::mutate(在警告消息中说明)覆盖plyr::mutate。要解决此问题,请先加载plyr,然后再加载dplyr,或者在mutate调用中显式引用dplyr:

out %>% group_by(site) %>% dplyr::mutate(row = paste0("corr", row_number()))

关于r - dplyr row_number排名错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33593791/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com