gpt4 book ai didi

r - 不断收到错误: Expecting a single value: [extent=2] in summarise

转载 作者:行者123 更新时间:2023-12-03 08:41:56 29 4
gpt4 key购买 nike

运行以下脚本时始终出现此错误-使用dplyr包中的summary

analysis <- df %>% group_by(Year, Week, YearWeek, Cad.Name, CamName, Abs.ID, Place.Name, Pull.Name) %>% 
summarise(visits=sum(Visits)) %>%
group_by(Year, Week, YearWeek, Cad.Name, CamName, Abs.ID, Place.Name) %>%
summarise(video=unique(Video.Name),visits=sum(Visits)) %>%
arrange(Year,Week)

Video.Name是一个问题,需要在汇总之前将其添加到groupby才能执行。在访问过程中,我需要按视频的唯一计数来总结-有什么想法吗?我不断收到这些错误:
Error: Expecting a single value: [extent=2].
In addition: Warning messages:
1: Factor `YearWeek` contains implicit NA, consider using `forcats::fct_explicit_na`
2: Factor `YearWeek` contains implicit NA, consider using `forcats::fct_explicit_na`

最佳答案

错误应该来自unique(Video.Name),它的length可以大于1,但是summarise每个组仅返回一行。我们可以将其包装在list中。

library(dplyr)
df %>%
group_by(Year, Week, YearWeek, Cad.Name, CamName,
Abs.ID, Place.Name, Pull.Name) %>%
summarise(visits=sum(Visits)) %>%
group_by(Year, Week, YearWeek, Cad.Name, CamName, Abs.ID, Place.Name) %>%
summarise(video=list(unique(Video.Name)),visits=sum(Visits)) %>%
arrange(Year, Week)

关于r - 不断收到错误: Expecting a single value: [extent=2] in summarise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61019023/

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