gpt4 book ai didi

r - Group_By 和 Sum() 给出了意想不到的结果

转载 作者:行者123 更新时间:2023-12-04 21:54:10 35 4
gpt4 key购买 nike

我从 excel 中导入了一个包含 1071 行和 16 列的文件,代表自 2005 年以来在巴西赢得能源拍卖的所有可再生能源项目。

> HIST <- read_excel("D:/Paulo/Desktop/2018 Historico Leiloes Total para R.xls", 
+ col_types = c("numeric", "text", "text",
+ "text", "text", "text", "date", "numeric",
+ "numeric", "numeric", "numeric",
+ "numeric", "numeric", "numeric",
+ "numeric", "numeric"))

> HIST
# A tibble: 1,071 x 16
Ano Leilao Fonte UF Vend
<dbl> <chr> <chr> <chr> <chr>
1 2011 2011 LER Bio SP Louis Dreyffus
2 2008 2008 Leilao 1 Bio MG CMAA
3 2008 2008 Leilao 1 Bio SP RAIZEN
4 2017 2017 A-4 PV PI Enel
5 2013 2013 A-5 2 PPEE BA CHESF
6 2008 2008 Leilao 1 Bio SP Abengoa
7 2008 2008 Leilao 1 Bio GO N/A
8 2009 2009 A-3 PPEE RS Eletrosul
9 2017 2017 A-4 PV BA SOLATIO SINDUSTRIAL
10 2009 2009 A-3 PPEE RS Eletrosul
# ... with 1,061 more rows, and 11 more variables: Projeto <chr>, CODPPA <dttm>,
# CAPEX <dbl>, MW <dbl>, GF <dbl>, FC <dbl>, PPA <dbl>, RMW <dbl>, WACC <dbl>,
# TIR <dbl>, VPL <dbl>

然后,我加载了 dplyr:
> library(dplyr)

最后,当我按 YEAR(葡萄牙语中的 ANO)分组并总结 MW(兆瓦)的总和时——我想知道每年拍卖了多少兆瓦——我得到了以下相当令人失望的结果:
HIST %>%
+ group_by(HIST$Ano)%>%
+ summarise(sum(HIST$MW))

# A tibble: 13 x 2
HIST$Ano sum(HIST$MW)
<dbl> <dbl>
1 2005 72677.67
2 2006 72677.67
3 2007 72677.67
4 2008 72677.67
5 2009 72677.67
6 2010 72677.67
7 2011 72677.67
8 2012 72677.67
9 2013 72677.67
10 2014 72677.67
11 2015 72677.67
12 2016 72677.67
13 2017 72677.67`

它不应该总结每年的MW吗?它显示MW的总和,并且每年重复该值。我究竟做错了什么?

谢谢你,保罗

最佳答案

尝试

HIST %>%
group_by(Ano) %>%
summarise(soma = sum(MW))

关于r - Group_By 和 Sum() 给出了意想不到的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48143680/

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