Hi folks,

I am trying to recurse through several numbered subfolders in a directory. Each 
folder has many trees that I want to display summary values for. I have been 
expanding data frames using code with the structure name <- rbind(name, 
newvals) to produce a data frame with n rows equal to the number of files in 
one of the folders, and n column equal to the number of values in the file.

I can loop over the values within a single subdirectory fine with, for example,

library(ape)

trees <- list.files(pattern="*.tre")
iters=length(trees)

branchdata.5 <- data.frame()

iterations <- as.character(c(1:length(trees)))

for (i in 1:iters) {

tree <- read.tree(trees[i])
iteration.edges.5 <- as.numeric(tree$edge.length)

branchdata.5 <- rbind(branchdata.5, iteration.edges.5)

}

The problem comes when I want to iterate through the numbered subdirectories 
while also iterating through the files in a given directory. I want to 
recursively assign these data frames as well, with something like

f <- list.dirs(path = "/.../.../etc", full.names = FALSE, recursive = FALSE)

for (j in 1:length(f)) {

setwd(paste("/.../.../.",j,sep=""))

assign( paste("branchdata.5",j,sep=""), data.frame() )

iterations <- as.character(c(1:length(trees)))

for (i in 1:iters) {

tree <- read.tree(trees[i])
assign(paste("iteration.edges.5",j,sep=""), as.numeric(tree$edge.length) )

paste("branchdata.5",j,sep="") <- rbind(paste("branchdata.5",j,sep=""), 
paste("iteration.edges.5",j,sep=""))

}

names(iterations) <- NULL
boxplot(t(paste("branchdata.5",j,sep="")) , horizontal=TRUE , names=iterations 
, ylim=c(0,2), xlab="Branch Lengths" , ylab="Iterations" , main = "")

}

The problem seems to be in the rbind() when using values with assign() and 
paste(). I would love some help on this! 


John S. S. Denton
Ph.D. Candidate
Department of Ichthyology and Richard Gilder Graduate School
American Museum of Natural History
www.johnssdenton.com
_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

Reply via email to