0

When I import a csv file using the read_csv function of the readr package, it adds leading zeros to a variable which was originally numerical but was imported as character automatically by read_csv. Any idea as to how I can ensure that read_csv does not add leading zeros to a numerical variable?

Anup
  • 239
  • 2
  • 11
  • 2
    `read_csv` is not documented for the `haven` package. Maybe you're using `readr`? If you show what you're doing, it might be tracked to the data rather than the function. – markhogue Mar 29 '21 at 15:58
  • Thanks. I have corrected it now in the post. – Anup Mar 29 '21 at 16:11
  • 3
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. It seems very unlikely that it would add 0s to the start of character values that were not there originally. – MrFlick Mar 29 '21 at 16:12
  • 2
    The `?read_csv` help page tells you how to specify column classes. I would suggest either specifying that the class of that column is numeric and/or investigating the values in that column to try to find any that don't look numeric to understand why `read_csv` is making the guess that it does. – Gregor Thomas Mar 29 '21 at 16:35

0 Answers0