[R] Varying name of output tables from looped process of list of spdf objects

SisoL cecilia.larrosa10 at imperial.ac.uk
Tue Jul 28 17:36:07 CEST 2015


Hi,

Thank you for the replies. I tried Peter's suggestions and this worked:

###Read forest shape files
setwd("/Users/sisolarrosa/Documents/PhD/R_work/AF/IIC/split_bf_fnp/")
shps<- dir(getwd(), "*.shp")
shps <- gsub('.{4}$', '', shps)
for (shp in shps) assign(shp, readOGR(".",layer=shp))

###Create list
afiles <- ls(pattern= "a_")

### Create Conefor Input Tables
for (ifile in 1:length(afiles))
{
  fnp<- mget(afiles[ifile])[[1]]
  distance.matrix<- gDistance(fnp, spgeom2= NULL, byid=T);
  row.names(distance.matrix) <- paste(1:nrow(distance.matrix), sep="");
  colnames(distance.matrix)<- paste(1:ncol(distance.matrix), sep="");
  dists.melt <-
melt(distance.matrix)[melt(upper.tri(distance.matrix))$value,];
  outfile <-
file.path("/Users/sisolarrosa/Documents/PhD/R_work/AF/IIC/conefor_inputs/",
paste0("distances_", afiles[ifile], ".txt"));
  write.table(dists.melt, outfile,row.names=FALSE, col.names=FALSE);
}



--
View this message in context: http://r.789695.n4.nabble.com/Varying-name-of-output-tables-from-looped-process-of-list-of-spdf-objects-tp4710369p4710491.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list