简体   繁体   中英

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. The issue is that R does not read the row of the years that follows 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.

在此处输入图像描述

I tried to change the format of the row of the years to number in excel, but it did not solve the problem.

I split the data and copied the years that follows 2007 to another sheet. 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. 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

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 "..".

Easily solved, though, specify the na string, eg, CPI <- read_excel(path = "...", na = "..")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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