Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
read_excel(来自readxl软件包)将1899-12-30年之前的日期读取为NA,如何解决此问题?_R - Fatal编程技术网

read_excel(来自readxl软件包)将1899-12-30年之前的日期读取为NA,如何解决此问题?

read_excel(来自readxl软件包)将1899-12-30年之前的日期读取为NA,如何解决此问题?,r,R,我有一个130场足球比赛的数据集,可以追溯到1893年 当我从Excel导入数据集时,1900年的日期与R(RStudio)中的日期相同。但是,1900年以前的日期被称为NAs 我如何修复它,使所有日期都以正确的格式来自Excel 或者,如何用正确的(18XX-MM-DD)日期替换NAs 这是Excel中显示的数据: Home_Team, Away_Team, SUFC, SWFC, H, A, Score, Season, Date Sheffield United, Sheff

我有一个130场足球比赛的数据集,可以追溯到1893年

当我从Excel导入数据集时,1900年的日期与R(RStudio)中的日期相同。但是,1900年以前的日期被称为NAs

我如何修复它,使所有日期都以正确的格式来自Excel

或者,如何用正确的(18XX-MM-DD)日期替换NAs

这是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)
库(tidyverse)
图书馆(readxl)
图书馆(magrittr)
图书馆(dplyr)
图书馆(GG2)
图书馆(tidyr)

Sheff_derby_R不管有什么缺陷,这里有一个可能的(临时)解决方法:

首先,读入
“text”
,看看R有点哽咽的原因。(我过度简化了这里的
read\u excel
参数,因为在这种情况下
日期的默认值是
“text”
。在您的情况下,只需在
列类型的向量中从
“Date”
更新为
“text”

库(readxl)

它实际上完全取决于Excel中1900年之前日期的格式以及您用来读取的R代码。考虑在这里共享你的R代码,也许发布一个链接到Excel的Doc文件上的DoppBox欢迎到StAccess。请参阅。分享您迄今为止尝试过的相关代码片段。这将有助于跟踪问题并获得专家的帮助。我将数据添加到问题中。这可能是
readxl
中的错误。作为一种解决方法,您可以尝试将
xlsx
导出为
csv
,然后使用
readr
软件包中的
read\u csv
进行读取。我同意@plant,将相关Excel数据导出为csv。我将您的数据复制到Excel中,并运行了您的代码。我的
Date
列都是NAs。我甚至无法通过将Excel中的单元格转换为类型
Date
,或者将数据转换为表格来改进它。
    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