简体   繁体   English

为什么 R 只读取从 Excel 导出的行的一半?

[英]Why R is only reading half of the row that is exported from Excel?

I am exporting data on inflation from Excel to R that extends from 1960 to 2020 in 29 countries.我正在导出从 Excel 到 R 的通货膨胀数据,该数据从 1960 年延伸到 2020 年,分布在 29 个国家/地区。 The issue is that R does not read the row of the years that follows 2007.问题是 R 没有读取 2007 年之后的年份行。

在此处输入图像描述

Another issue is that the years columns are read as character by R from 1960 until 1997. Then it changes to double as you can see in the picture below.另一个问题是,从 1960 年到 1997 年,R 将年份列读取为character 。然后它变为double ,如下图所示。

在此处输入图像描述

I tried to change the format of the row of the years to number in excel, but it did not solve the problem.我尝试将excel中的年份行格式更改为number ,但没有解决问题。

I split the data and copied the years that follows 2007 to another sheet.我拆分数据并将 2007 年之后的年份复制到另一张表中。 Then i was able to export it (years of 2008 to 2020) separately and R was able to read the first row of the years with no problem whatsoever.然后我能够单独导出它(2008 年到 2020 年),并且 R 能够毫无问题地读取第一行。 I am not sure what that means.我不确定那是什么意思。 But my aim is to export all the data at once from the same sheet.但我的目标是一次从同一张表中导出所有数据。 Could someone help me with that please?有人可以帮我吗?

Here is the code:这是代码:

library(readxl)
CPI <- read_excel("~/Desktop/Excel sheets/CPI.xlsx")

Here is the data:这是数据:

https://docs.google.com/spreadsheets/d/14Xrr_0Beul4fA2LD6YIeEiBP58P0SMoF/edit?usp=sharing&ouid=100310480084555611403&rtpof=true&sd=true https://docs.google.com/spreadsheets/d/14Xrr_0Beul4fA2LD6YIeEiBP58P0SMoF/edit?usp=sharing&ouid=100310480084555611403&rtpof=true&sd=true

Your issue is that missing values are denoted with "..", so read_excel() considers these cells as characters and so marks the whole column as a character, where there is a "..".您的问题是缺失值用“..”表示,因此read_excel()将这些单元格视为字符,因此将整列标记为一个字符,其中有一个“..”。

Easily solved, though, specify the na string, eg, CPI <- read_excel(path = "...", na = "..")但是,很容易解决,指定na字符串,例如, CPI <- read_excel(path = "...", na = "..")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM