r - nested for loop to create histograms named according to list -


i'm new r , need create bunch of histograms named according population came from. when try running loop without "names" part, works fine. code below loops through list of names , applies them in order, end 3,364 versions of same exact histogram. if has suggestions, i'd appreciate it.

popfiles <- list.files(pattern = "*.txt") # generates list of files i'm working poptables <- lapply(popfiles, read.table, header=true, na.strings="na") popnames <- read.table(file.path("path file containing names", "popnamesr.txt"), header=false,) popnames <- as.matrix(popnames)  name <- null table <- c(1:58)  (table in poptables){    (name in popnames){        pvals <- table$p        hist(pvals, breaks=20, xlab="p-val", main=name))    } } 

try making distinct iterator, , use that, rather iterating on table list itself. it's easier see what's going on. example:

pdf("myhistograms.pdf")     for(i in 1:length(poptables)){     table = poptables[[i]]     name = popnames[i]     pvals = table$p     hist(pvals, breaks=20, xlab="p-val", main=name)) } dev.off() 

in case, problem name , table linked, have 2 loops, every combination of table , name generated.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -