I need to apply a set of commands in R to all the individual .txt
files (around 300) in a directory.
I'm not very familiar with R, so all the help I've looked at online about looping is confusing, or I can't work out how to apply a loop when you need to apply multiple commands to each file.
The commands I need to apply to each file (phylogenetic trees) within the directory are (which uses R's ape library):
testtree <- read.tree("tree123.txt")
unrooted_tr <- unroot(testtree)
write.tree(unrooted_tr, file="unrootedtree123.txt")
How do I apply a loop which will apply these commands to each individual .txt file (either using R or in the Unix command line)? The output (e.g. unrootedtree123.txt) will need to have a different name for each individual file.
Thanks in advance, Dani.