I have a Spanish computer and am working in a French language environment, where the decimal separator is usually a comma. I am more used to working with periods as decimal separators, so changed the separator in Microsoft Excel and also specified the separator when reading in the file to R as below:
eg <- read.csv("D:/02_COVID-19/Analysis/eglonglat.csv", dec = ".", sep = ",", header = TRUE, stringsAsFactors = FALSE)
However, it seems that the comma separator is being ignored, because the .csv has three columns and when read into R it has only one column.
I´m using a clean install of R 4.0 and RStudio 1.3.959 on a Windows 7 laptop.
Any ideas? I was only trying to copy some example data from a stack overflow post that used periods as decimal separators - not sure whether it is the intervention of excel that is causing the problem here (it looks like the decimal separators are periods but maybe they are not in the background?)
Here is what the output looks like in R after being read in:
> eg
index.lat.lon
1 1;51.513393;-0.11565
2 2;51.513428;-0.115461
3 3;51.513428;-0.115462
4 4;51.513428;-0.115465
5 5;51.513428;-0.11547
6 6;51.513432;-0.115462
7 7;51.513432;-0.115467
8 8;51.513435;-0.115471
9 9;51.513439;-0.115468
10 10;51.513439;-0.115469
In read.csv
, you need sep = ";"
to separate columns and dec = ","
to consider decimals with comma separator.
eg <- read.csv("D:/02_COVID-19/Analysis/eglonglat.csv", sep = ";", dec = ",")
These are default settings in read.csv2
eg <- read.csv2("D:/02_COVID-19/Analysis/eglonglat.csv")
Since you are on R 4.0.0, you don't need stringsAsFactors = FALSE
.
Debugging further it seems OP has "."
as decimal separator so this works :
eg <- read.csv("D:/02_COVID-19/Analysis/eglonglat.csv", sep = ";")