Its better to do using lapply
to load everything first and then use melt
as follows: (Assuming all your files are in the variable files
,
Note: Untested
require(reshape2)
files <- list.files(my.dir, full.names = TRUE)
# first load all files
dd <- lapply(1:length(files), function(idx) {
d <-read.csv(files[idx], header = TRUE, sep=",", check.names = FALSE)
# if you want the file index
d$file.idx <- idx
d
})
# merge all
dd <- do.call(rbind, dd)
# now melt
dd.m <- melt(dd, c(4:length(d)), c("date.time","tag"), variable.name = "receiver")
Edit: After Op's edit
Note: Untested
require(reshape2)
files <- list.files(my.dir, full.names = TRUE)
dd.m <- lapply(1:length(files), function(idx) {
# load the file
d <-read.csv(files[idx], header = TRUE, sep=",", check.names = FALSE)
# now melt immediately
d.m <- melt(d, c("date.time","tag"), c(4:length(d)))
})
# merge all
dd.m <- do.call(rbind, dd.m)