Skip to main content

Reading a file with decimals

Posted in

I have a file with decimals and regular numbers on it. For some reason, even though the decimal is set correctly as '.' it is added as a factor. All of the columns that do not have a decimal are correctly processed as integers. I'm not sure if this is a problem with Red-R, or if it's me doing something wrong.

No it doesn't I got the file just fine.

Like I said it worked exactly as expected. I only had one factor column and it was text. All others were integer, numeric, or logical for the empty ones.

Hi Covingto,
CSV are just Comma Separated Values. It's just a regular text file.
Would you prefer I upload it as a .txt? It shouldn't really matter though.
Thanks!
Daniel

Sorry it was a csv from the beginning.

I have no problem reading it in. The only factor column I get is ENTIDAD.FEDERATIVA.

I have the following settings;
file type; text
column separator; comma
column headers; checked
fill; not checked
quote; "
decimal; .
lines to scan; 10
lines to skip; 0

Try forcing to numeric using the radio buttons, or make sure that you have deximal set to . instead of '.'

it's probably like that anyway.

Kyle

Not sure if the coding matters. It all happens in R. Can you try to save as different format (csv?)?

Kyle

Hi, I'm setting the headers as true. I've uploaded the file so you can test it out yourself:
http://bandartech.com/test.csv
The last columns are the ones that are being marked as factors.
I couldn't find any other characters inside of the decimal.
Does the encoding matter? I have my files under utf 8.
Thanks a lot,
Daniel

I'll look into it. I regularly read in data files with '.' set as the decimal and have no problem.

I just read in a file to test and they are being entered as numeric.

You should be able to change the radio buttons so that the factor columns that are in by mistake are read in as whatever format you want.

One thing, are you setting column headers to true? If you have any text in the column at all it will pick factor. You might want to look at your file in a spreadsheet program just to make sure.

edit- there might also be an issue with extra spaces or quotes in the integers.

Kyle