2
votes

I have to read an excel file in R. The excelfile has a column with values such as 50%,20%... and another column with dates in the format "12-December-2017" but R converts both the column datas.

I am using readxl package and i specified in col_types parameter all the columns to be read as text but when i check the dataframe all the column types are characters but the percentage data and date changes to decimals and numbers respectively.

 excelfile2<-read_excel(filePath,col_types=rep("text",8))

I want to read the excel file as is.Any help will be appreciated.

1

1 Answers

0
votes

This is because what you visualize inside the Excel is not what actually is stored.
For example, if in excel you visualize "12-December-2017", what is stored in reality is the number of days since 1-1-1899.

My suggestion is to open the Excel file with the TextReader so you have a grasp what really you are reading in R.

Then, you can either define everything as text in excel or you can apply some transformations in R in order to convert the days since 1-1-1899 into a POSIXct format.