I've got some basic code for reading in multiple files from a folder that share the same file format. The text files themselves each contain one or two sentences; no columns, headers or anything like that.
I initally used read.table to do this but after doing some reading round and in particular looking at this recent post I thought I'd see if I could use fread to make things a little bit quicker.
library(data.table)
files <- list.files(path = "C:/Documents", pattern = "*.txt")
readdata <- function(x)
{
mydata <- fread(x, sep=" ")
return(mydata)
}
all.files <- lapply(files, readdata)
final.data <- rbindlist(all.files)
When I run this code, I get the following error:
Error in fread(x, sep = " ") : File not found: 1.txt
1.txt is the first file in the folder. Can anyone figure out why this? The path folder is correct (I changed the one above to something generic to put on here) so I can't seem to see what the problem is.
setwd("C:/Documents")
? – Sven Hohenstein