将点差应用于润滑包的湖人队数据集时出错
Error in the application of the spread to the lakers data set of the lubricated package
我正在尝试分析 2008 年至 2009 年间每个湖人队球员得分多少,并根据 lubridate 包的数据集 lakers 呈现每年的结果。
我正在尝试以下代码:
date <- lubridate :: lakers
date <- date %>%
mutate (Year = str_sub (date, 1, 4))%>%
filter (points> 0 & team == 'LAL')%>%
select (Year, player, points)%>%
group_by (Year, player)%>%
summarise (Total_points = sum (points))%>%
ungroup ()%>%
spread (player, points)
但是传播失败,报如下错误:
Erro: Must extract column with a single valid subscript.
x Subscript `var` has the wrong type `function`.
ℹ It must be numeric or character.
我想知道是什么问题。感谢您的帮助。
唯一的问题是你忘记了你在总结points
的时候给它起了Total_points
的名字。您在最后一行调用 points
。此错误表示未找到您的变量。只需更正最后一行中的变量名称:
date <- lubridate :: lakers
date <- date %>%
mutate(Year = (str_sub(date, 1, 4))) %>%
filter(points> 0 & team == 'LAL')%>%
select(Year, player, points)%>%
group_by(Year, player) %>%
summarise(Total_points = sum(points))%>%
ungroup()%>%
spread(player, Total_points)
我正在尝试分析 2008 年至 2009 年间每个湖人队球员得分多少,并根据 lubridate 包的数据集 lakers 呈现每年的结果。
我正在尝试以下代码:
date <- lubridate :: lakers
date <- date %>%
mutate (Year = str_sub (date, 1, 4))%>%
filter (points> 0 & team == 'LAL')%>%
select (Year, player, points)%>%
group_by (Year, player)%>%
summarise (Total_points = sum (points))%>%
ungroup ()%>%
spread (player, points)
但是传播失败,报如下错误:
Erro: Must extract column with a single valid subscript.
x Subscript `var` has the wrong type `function`.
ℹ It must be numeric or character.
我想知道是什么问题。感谢您的帮助。
唯一的问题是你忘记了你在总结points
的时候给它起了Total_points
的名字。您在最后一行调用 points
。此错误表示未找到您的变量。只需更正最后一行中的变量名称:
date <- lubridate :: lakers
date <- date %>%
mutate(Year = (str_sub(date, 1, 4))) %>%
filter(points> 0 & team == 'LAL')%>%
select(Year, player, points)%>%
group_by(Year, player) %>%
summarise(Total_points = sum(points))%>%
ungroup()%>%
spread(player, Total_points)