Hi Cecilia, print(fnp) and print(a_10) are not exactly the same
>> print(fnp) > $a_10 > class : SpatialPolygonsDataFrame vs. >> print(a_10) > class : SpatialPolygonsDataFrame Looks like mget returns a list. Can you try: fnp <- get(afiles[ifile])[1] print(fnp) #the $a_10 should be gone. cheers Peter > On 27 Jul 2015, at 18:33, SisoL <cecilia.larros...@imperial.ac.uk> wrote: > > Hi Peter, > > Thank you for your reply. The method for looping seems to work, but > gDistance will not recognise the input. I am puzzled because when I > print(fnp), and print (a_10) they look exactly the same, but when I try to > run gDistance{rgeos} with a_10 it works, but with fnp it throws an error. > Please see below. Any other suggestions? > >> afiles <- ls(pattern= "a_") #OK >> print(afiles) > [1] "a_1" "a_10" > >> fnp<- mget(afiles[ifile]) #OK > >> print(fnp) > $a_10 > class : SpatialPolygonsDataFrame > features : 5 > extent : 825796.9, 831270.1, 815666.9, 816562.5 (xmin, xmax, ymin, > ymax) > coord. ref. : +proj=aea +lat_1=-5 +lat_2=-42 +lat_0=-32 +lon_0=-60 +x_0=0 > +y_0=0 +ellps=aust_SA +units=m +no_defs > variables : 5 > names : ID, GRIDCODE, Shape_Leng, Shape_Area, Count > min values : 1, 1, 94.2722341164, 6.47354525991, 1 > max values : 5, 1, 2305.45647624, 92111.8528756, 1 > >> print(a_10) > class : SpatialPolygonsDataFrame > features : 5 > extent : 825796.9, 831270.1, 815666.9, 816562.5 (xmin, xmax, ymin, > ymax) > coord. ref. : +proj=aea +lat_1=-5 +lat_2=-42 +lat_0=-32 +lon_0=-60 +x_0=0 > +y_0=0 +ellps=aust_SA +units=m +no_defs > variables : 5 > names : ID, GRIDCODE, Shape_Leng, Shape_Area, Count > min values : 1, 1, 94.2722341164, 6.47354525991, 1 > max values : 5, 1, 2305.45647624, 92111.8528756, 1 > >> distance.matrix<- gDistance(fnp, spgeom2= NULL, byid=T) > Error in (function (classes, fdef, mtable) : > unable to find an inherited method for function ‘is.projected’ for > signature ‘"list"’ > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Varying-name-of-output-tables-from-looped-process-of-list-of-spdf-objects-tp4710369p4710408.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.