I have 10 files, for simplicity let's call them A: J. I wish to read them in using a for
loop that reads them in and assigns them a name from a vector of names.
This is my code:
i=1:10
name<-c("A", "B", "C", "D", "E", "F","G","H","I","J")
file<-c("A.txt", "B.txt", "C.txt", "D.txt", "E.txt",
"F.txt","G.txt","H.txt","I.txt","J.txt")
for (i in 1:7){
tmp<-read.table(file[i],sep="\t",header=TRUE) %>%
assign(name[i])
}
This results in:
Error in assign(., species[i]) : invalid first argument
An alternative approach to @user2974951 would be to save all the files in a list caled dataFiles.
I here use LETTERS to assign names, but could be just as well be: