r - make csv data import case insensitive -


i realize total newbie 1 (as in case), i'm trying learn r, , need import hundreds of csv files, have same structure, in column names uppercase, , in lower case.

so have (for now)

flow0300csv  <- sys.glob("./csvfiles/*0300*.csv")  (filename in flow0300csv) {         flow0300 <- read.csv(filename, header=t,sep=";",    colclasses = "character")[,c('code','class','name')]  } 

but error because of lower cases. have tried apply "tolower" can't make work. tips?

the problem here isn't in reading csv files, it's in trying index using column names don't exist in "lowercase" data frames.

you can instead use grep() ignore.case = true index columns want.

tmp <- read.csv(filename, header = t, sep = ";",                 colclasses = "character") ind <- grep(patt = "code|class|name", x = colnames(tmp),              ignore.case = true) tmp[, ind] 

you may want readr::read_csv2() or data.table::fread() better performance.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -