Ah, but they don't look exactly the same. Look closer at the first line of the print() output.
You might also look at class(fnp) class(a_10) for a clue. What happens if you run: distance.matrix<- gDistance(fnp[[1]], spgeom2= NULL, byid=T) Sarah On Mon, Jul 27, 2015 at 12:33 PM, 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"’ > -- Sarah Goslee http://www.functionaldiversity.org ______________________________________________ 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.