Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88075

read.xlsx file with one column consisting "numbers as text"

$
0
0

I have excel file that contains numeric variables, but the first column (index column) uses custom formatting: those are numbers that should be presented as text (or similar to text) and having always fixed number of digits where some are zeroes. Here is my example table from excel:

enter image description here

And here is formatting for bad_col1 (rest are numbers or general):

enter image description here

When I try to import my data by using read.xlsx function from either openxlsx or xlsx package it produces something like this:

read.xlsx(file_dir,sheet=1)#for openxlsx

  bad_col1 col2 col3
1        5   11  974
2      230   15  719
3    10250    6  944
4     2340    7  401

So as you can see, zeroes are gone. Is there any way to read 1st column as "text" and as other numeric? I can not convert it to text after, because "front zeroes" are gone arleady. I can think of workaround, but it would be more feasible for my project to have them converted while importing.

Thank you in Advance


Viewing all articles
Browse latest Browse all 88075

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>