r语言 - 尝试加载 CSV 文件以进行nfl_elo;缺少参数"dat",没有默认值



当它说dat时,我不知道它在要求什么。 我一直在尝试从项目[538]的网站获取数据以供下载。我无法直接从该网站下载它,所以我将其下载为

nfl_eloRAW <- read_csv("https://projects.fivethirtyeight.com/nfl-api/nfl_elo.csv")

然后,我将其应用于"FiveThirtyEight"包中的推荐下载格式。

> nfl_elo <- read_csv((nfl_eloRAW), clean_names(), mutate( team1 = 
as.factor(team1), team2 = as.factor(team2), neutral = ifelse(neutral == 1, 
TRUE, FALSE)), is.data.frame(dat))
Error in is.data.frame(dat) : argument "dat" is missing, with no default

当我使用数据框直接写为:

library(tidyverse) library(janitor) 
nfl_elo <- read_csv("https://projects.fivethirtyeight.com/nfl-api/nfl_elo.csv") 
clean_names() mutate( team1 = as.factor(team1), team2 = as.factor(team2), 
neutral = ifelse(neutral == 1, TRUE, FALSE))

我收到错误:

nfl_elo中的意外项目:"clean_names((">

我有整理,所以它应该可以工作。我还是新手,所以任何建议都很棒。我认为 dat 中的错误可能意味着数据,数据确实在我的全局环境中上传。 我可以将文件下载到 excel 中并导入数据集,也许可以避免尝试格式化时出现其中一些问题,但我喜欢如果它是从网站上的直接补丁上传的,它会在每场比赛后更新。

嘿,欢迎来到stackoverflow,你只是缺少%>%管道运算符将你的函数连接在一起。另外,我建议您缩进代码,使其更具可读性。

我运行了下面的代码以获得以下输出

library(tidyverse)
library(janitor) 
nfl_elo <- read_csv("https://projects.fivethirtyeight.com/nfl-api/nfl_elo.csv") %>% 
clean_names() %>%
mutate(
team1 = as.factor(team1), 
team2 = as.factor(team2),
neutral = ifelse(neutral == 1, TRUE, FALSE)
)
nfl_elo
# A tibble: 16,274 x 14
date season neutral playoff  team1  team2 elo1_pre elo2_pre elo_prob1 elo_prob2 elo1_post elo2_post score1
<date>  <int>   <lgl>   <chr> <fctr> <fctr>    <dbl>    <dbl>     <dbl>     <dbl>     <dbl>     <dbl>  <int>
1 1920-09-26   1920   FALSE    <NA>    RII    STP 1503.947 1300.000 0.8246512 0.1753488  1516.108  1287.838     48
2 1920-10-03   1920   FALSE    <NA>    BFF    WBU 1478.004 1300.000 0.8020003 0.1979997  1489.757  1288.247     32
3 1920-10-03   1920   FALSE    <NA>    CBD    PTQ 1504.688 1300.000 0.8252672 0.1747328  1516.803  1287.885     48
4 1920-10-03   1920   FALSE    <NA>    CHI    MUT 1368.333 1300.000 0.6829856 0.3170144  1386.533  1281.800     20
5 1920-10-03   1920   FALSE    <NA>    RII    MUN 1516.108 1478.004 0.6441711 0.3558289  1542.135  1451.977     45
6 1920-10-03   1920   FALSE    <NA>    DAY    COL 1493.002 1504.908 0.5758191 0.4241809  1515.434  1482.475     14
7 1920-10-03   1920   FALSE    <NA>    RCH    ABU 1503.420 1300.000 0.8242121 0.1757879  1510.934  1292.486     10
8 1920-10-03   1920   FALSE    <NA>    AKR    WHE 1503.420 1300.000 0.8242121 0.1757879  1515.278  1288.142     43
9 1920-10-10   1920   FALSE    <NA>    CBD    TLM 1516.803 1300.000 0.8350967 0.1649033  1527.799  1289.004     42
10 1920-10-10   1920   FALSE    <NA>    CHI    KEW 1386.533 1300.000 0.7052228 0.2947772  1402.774  1283.760     25
# ... with 16,264 more rows, and 1 more variables: score2 <int>

最新更新