0

My data frame contains five character columns and one numeric column. When I export the data frame all columns convert to strings including the numeric column. How do I avoid this?

The structure of my data frame:

Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   3194 obs. of  6 variables:
 $ State_FIPS_Code         : chr  "00" "01" "01" "01" ...
 $ County_FIPS_Code        : chr  "000" "000" "001" "003" ...
 $ Postal_Code             : chr  "US" "AL" "AL" "AL" ...
 $ Name                    : chr  "United States" "Alabama" "Autauga County" "Baldwin County" ...
 $ Poverty_Percent_All_Ages: num  14.7 18.5 12.7 12.9 32 22.2 14.7 39.6 25.8 20 ...
 $ geoid                   : chr  "00000" "01000" "01001" "01003" ...

Export code:

write.csv(dfGeoid, file = "MyData.csv", row.names=T)
Tdebeus
  • 1,519
  • 5
  • 21
  • 43
  • What exactly is the evidence that all columns are written as strings? You haven't clearly described the problem. It would help if you provided a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Aug 04 '17 at 14:25
  • Text files have no data types. There’s no distinction between “string” and numeric data. It’s all just text. In particular, CSV files do not preserve any type information. When you load a CSV file in R, R therefore has to guess the column data types (or you can tell it). It sometimes guesses wrongly. – Konrad Rudolph Aug 04 '17 at 14:45
  • Ah of course @KonradRudolph that seems very logical. Forgot about that. – Tdebeus Aug 04 '17 at 15:00

0 Answers0