我有一个包含 130 场足球比赛的数据集,这些比赛的历史可以追溯到 1893 年。
当我从 Excel 导入数据集时,1900 年的日期与 R (RStudio) 中应有的日期相同。但是,1900 年之前的日期以 NA 形式出现。
我该如何解决这个问题,以便所有日期都以正确的格式来自 Excel?
或者,如何用正确的 (18XX-MM-DD) 日期替换 NA?
这是 Excel 中显示的数据:
Home_Team, Away_Team, SUFC, SWFC, H, A, Score, Season, Date
Sheffield United, Sheffield Wednesday, 1, 1, 1, 1, 1–1, 1893/94, 1893-10-16
Sheffield United, Sheffield Wednesday, 1, 0, 1, 0, 1–0, 1894/95, 1895-01-12
Sheffield United, Sheffield Wednesday, 1, 1, 1, 1, 1–1, 1895/96, 1895-12-26
Sheffield United, Sheffield Wednesday, 2, 0, 2, 0, 2–0, 1896/97, 1896-12-26
Sheffield United, Sheffield Wednesday, 1, 1, 1, 1, 1–1, 1897/98, 1897-12-27
Sheffield United, Sheffield Wednesday, 2, 1, 2, 1, 2–1, 1898/99, 1898-12-26
Sheffield United, Sheffield Wednesday, 1, 0, 1, 0, 1–0, 1900/01, 1900-12-15
Sheffield United, Sheffield Wednesday, 3, 0, 3, 0, 3–0, 1901/02, 1902-03-01
Sheffield United, Sheffield Wednesday, 2, 3, 2, 3, 2–3, 1902/03, 1902-09-01
Sheffield United, Sheffield Wednesday, 1, 1, 1, 1, 1–1, 1903/04, 1903-12-12
Sheffield United, Sheffield Wednesday, 4, 2, 4, 2, 4–2, 1904/05, 1905-04-08
Sheffield United, Sheffield Wednesday, 0, 2, 0, 2, 0–2, 1905/06, 1905-10-21
这是我应用到它的 R 代码:
library(tidyverse)
library(readxl)
library(magrittr)
library(dplyr)
library(ggplot2)
library(tidyr)
Sheff_derby_R <- read_excel("sheffield_derby/Sheff_derby_R.xlsx",
col_types = c("text", "text", "text",
"text", "text", "text", "text",
"text",
"date", "text", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "text"))
View(Sheff_derby_R)
在 R 中,18xx 日期(最后一栏,不是 18xx/xx 季节栏)被 NA 替换。这是头部,前 12 行:
Home_Team Away_Team SUFC SWFC H A Score Season Date
<chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <dttm>
1 Sheffiel~ Sheffiel~ 1 1 1 1 1 – 1 1893/~ NA
2 Sheffiel~ Sheffiel~ 1 0 1 0 1 – 0 1894/~ NA
3 Sheffiel~ Sheffiel~ 1 1 1 1 1 – 1 1895/~ NA
4 Sheffiel~ Sheffiel~ 2 0 2 0 2 – 0 1896/~ NA
5 Sheffiel~ Sheffiel~ 1 1 1 1 1 – 1 1897/~ NA
6 Sheffiel~ Sheffiel~ 2 1 2 1 2 – 1 1898/~ NA
7 Sheffiel~ Sheffiel~ 1 0 1 0 1 – 0 1900/~ 1900-12-15 00:00:00
8 Sheffiel~ Sheffiel~ 3 0 3 0 3 – 0 1901/~ 1902-03-01 00:00:00
9 Sheffiel~ Sheffiel~ 2 3 2 3 2 – 3 1902/~ 1902-09-01 00:00:00
10 Sheffiel~ Sheffiel~ 1 1 1 1 1 – 1 1903/~ 1903-12-12 00:00:00
11 Sheffiel~ Sheffiel~ 4 2 4 2 4 – 2 1904/~ 1905-04-08 00:00:00
12 Sheffiel~ Sheffiel~ 0 2 0 2 0 – 2 1905/~ 1905-10-21 00:00:00