[R] rbind common header to file list
m||uj|@b @end|ng |rom gm@||@com
Wed Jan 20 00:45:53 CET 2021
I have more than 200 text files in a folder without header - example below.
I would like to read, add a common date header to all the files, and write
(replace) the files.
## Read files
filelist = list.files(pattern = ".*.txt")
datalist = lapply(filelist, function(x)read.table(x, header=F))
## What I want to add
date <- 20000101
datalist _new <- lapply(datalist, function(x) rbind(x, date))
How do I add this date as a common header and replace the files? Any help
will be highly appreciated. Thank you.
## Sample data
xy <- dput(head(x,6))
structure(list(V1 = c("-5.28082885742185,-0.509039307",
)), row.names = c(NA, 6L), class = "data.frame")
[[alternative HTML version deleted]]
More information about the R-help