Hello,
I have this R script:
#!/usr/bin/env Rscript
library(ggplot2)
Pai <- read.csv("abc.txt", sep = "\t")
colnames(Pai) <- c("nt","a","c","g","t")
Pai[2:5] <- scale(Pai[2:5])
write.table(Pai, file = "PaiZscore.txt", row.names = FALSE)
pdf("abc.pdf")
ggplot() +
geom_line(aes(Pai$nt,Pai$t), color = 'red') +
theme_classic()
dev.off()
It runs one file abc.txt and create one pdf abc.pdf. How can I modify this script so that it can run as a loop, use 200 files as input (abs1.txt, abc2.txt.........abc200.txt) and creates 200 pdfs (abs1.pdf, abc2.pdf.........abc200.pdf)?
The abc.txt files is generated using multiple custom pipelines, which incorporated bowtie, samtools, bedtools, and piPipes. I can use the aforementioned tools, but I am no expert in R. My goal is to make the heatmap of the final result in R.
Thanks a ton!!
Check For and While loops in R https://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf
Or,
lapply
that function over a list of file names. Avoid loops.