[问题] dplyr流程下如何汇出data.frame

楼主: studioA (understand?)   2022-06-30 12:55:41
[问题类型]:
程式咨询(我想用R 做某件事情,但是我不知道要怎么用R 写出来)
[软件熟悉度]:
入门(写过其他程式,只是对语法不熟悉)
[问题叙述]:
我有一组数据(IDW_table) ,我想处理分组计算后,另存成一个data.frame
但目前结果只能显示在console,无法另存起来,不知道哪里写错了,请给个指教
下列是我的资料格式 (范例档https://reurl.cc/0pMROo)
yearmon actual predicted
202101 11.3 10.626
202101 11.3 10.805
202102 11.2 10.78
202103 11.1 10.727
[程式范例]:
library(dplyr)
x <- data.frame(stringsAsFactors = F)
IDW_table%>%
select(yearmon,actual,predicted)%>%
group_by(yearmon) %>%
summarise( RMSE = sqrt(1/length(actual)*sum((actual-predicted)^2)) )%>%
as.data.frame()%>%
rbind.data.frame(x)
我自己尝试成功了 但这好像不能删文,所以我就把成功的部份写出来,献丑
x <- IDW_table%>%
select(yearmon,actual,predicted)%>%
group_by(yearmon) %>%
summarise( RMSE = sqrt(1/length(actual)*sum((actual-predicted)^2)) )%>%
as.data.frame()
[环境叙述]:
请提供 sessionInfo() 的输出结果
R version 4.1.3 Patched (2022-03-10 r81883)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
other attached packages:
[1] dplyr_1.0.9
[关键字]:
选择性,也许未来有用
楼主: studioA (understand?)   2022-06-30 13:09:00
我好像自己解决了
作者: locka (locka)   2022-06-30 18:17:00
哈哈 恭喜解决!自己解决超有成就感的XD

Links booklink

Contact Us: admin [ a t ] ucptt.com