I have a problem processing filename as variable in a loop in R
files <- list.files(pattern = "*.tab",full.name=T)
for (a in files) { aname <- strsplit(basename(a), "\\.")[[1]][1]
aname <- read.table(a,header=TRUE, sep="\t",comment.char="")
}
It produces only one object: aname
, if I use following:
for (a in files) { c(strsplit(basename(a), "\\.")[[1]][1]) <- read.table(a,header=TRUE,
sep="\t",comment.char="")
}
it produces: could not find function "c<-". But if I do
for (a in files) { aname <- strsplit(basename(a), "\\.")[[1]][1]
print(aname)
}
The output is a list of files without extension, as expected. So, the question is: how do I make result of a function a variable name? Thank you!