Tutorial by Examples

Importing using base R Comma separated value files (CSVs) can be imported using read.csv, which wraps read.table, but uses sep = "," to set the delimiter to a comma. # get the file path of a CSV included in R's utils package csv_path <- system.file("misc", "exDIF.csv&q...
The data.table package introduces the function fread. While it is similar to read.table, fread is usually faster and more flexible, guessing the file's delimiter automatically. # get the file path of a CSV included in R's utils package csv_path <- system.file("misc", "exDIF.csv&q...
Many people don't make use of file.path when making path to a file. But if you are working across Windows, Mac and Linux machines it's usually good practice to use it for making paths instead of paste. FilePath <- file.path(AVariableWithFullProjectPath,"SomeSubfolder","SomeFileNam...
Exporting using base R Data can be written to a CSV file using write.csv(): write.csv(mtcars, "mtcars.csv") Commonly-specified parameters include row.names = FALSE and na = "". Exporting using packages readr::write_csv is significantly faster than write.csv and does not ...
files = list.files(pattern="*.csv") data_list = lapply(files, read.table, header = TRUE) This read every file and adds it to a list. Afterwards, if all data.frame have the same structure they can be combined into one big data.frame: df <- do.call(rbind, data_list)
Fixed-width files are text files in which columns are not separated by any character delimiter, like , or ;, but rather have a fixed character length (width). Data is usually padded with white spaces. An example: Column1 Column2 Column3 Column4Column5 1647 pi 'important' ...

Page 1 of 1