I am trying to use a loop to manipulate multiple files but also to retain the names of the variables / outputs in each loop cycle.
Here is an example of what I am trying to do:
#define my source
SourceDir <- file.path('where/it/is')
#define my array
Wpns <- ('Bren', 'Welrod', 'Vickers')
#start for-loop
for (Wpn in Wpns){
#example of for loop contents 1 (is this a sensible way to get a file path?)
WpnFile <- file.path(paste0(SourceDir, '/My'_, Wpn, '_File.txt')
#example of for loop contents 2
WpnDataFrame <- read_delim(WpnFile, ' ')
}
So what I want now is to have six variables (well the last three are data frames) that I could call to look at. Obviously what I am actually going to do is overwrite WpnFile
and WpnDataFrame
over and over.
BrenFile
WelrodFile
VickersFile
BrenDataFrame
WelrodDataFrame
VickersDataFrame
This is the very first time I have used r so I wouldn't be surprised if what I have written (or maybe what I am trying to achieve) looks bizarre.
(For some context if it matters: I'm trying to manipulate and then plot data from text file. However I really need to check each stage of my for-loop (e.g. the data frames I create), so that I can check what I'm doing. This is also key in helping me visualise the changes I am making, as I am not used to working with matrices and additionally I may need toto return to specific data frames later.)