Read.CSV Doesn't Seem to Detect Factors in R 4.0.0

Factor variable shown as character variable in data frame after recent R update from 3.5.2 to 4.0.1

From what I now, you have two options:

  1. Set options(stringsAsFactors = TRUE) at every start of your R scripts.
  2. Set options(stringsAsFactors = TRUE) on your .Rprofile

Does converting character columns to factors save memory?

Converting to factor won't save space because characters are stored in a hash table. See section 1.10 The CHARSXP cache of R Internals.

Converting to factor may improve processing time if your code would need to convert to factor (running a regression, classification, etc.), but it won't improve processing time if you're doing string manipulation because it would have to convert the factor back to a character. So it really depends on what you're doing.

Comma separator ignored when reading in .csv files to R on a Spanish computer

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 = ";")


Related Topics



Leave a reply



Submit