I have a bunch of txt-files and want to write a loop that reads the whole respective file and writes its content (as a single string) to a dataframe. Here's the code:
file.names <- dir(path, pattern = "*.txt", recursive = TRUE, full.names = TRUE)
df1 <- data.frame(matrix(ncol = 1, nrow = 0))
colnames(df1) <- "string"
for(i in 1:length(file.names)){
df2 <- read_file(file.names[i])
dataframe <- rbind(df1, df2)
}
The loop doesn't work - I only read one file and write its content as the name of the column. I want the string content of every txt-file to represent one observation/row in the dataframe. Thanks a lot for your time and effort!