我无法弄清楚它说dat
时的要求。我一直在尝试从project [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()”
我正在进行tidyverse,因此应该可以。我还是新手,所以任何建议都很棒。我认为dat中的错误可能意味着数据,该数据确实已在我的全局环境中上传。 我可以将文件下载到excel中并导入数据集,也许可以避免尝试格式化时出现的一些问题,但是我喜欢如果它是从网站上的直接补丁上载的,它将在每次游戏后进行更新。
答案 0 :(得分:3)
欢迎使用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>