I apologize for raising the same topic from time to time,
but each time I have to subset  Spatial*DataFrame
objects (where * stands for polygons, lines or points) I
get some problems.

Last year Roger was kindly advising:
"Just think of Spatial*DataFrame objects as data.frame objects and things
will be much clearer"

Nevertheless, when I have to subset my lines now, I find that, given
> str(fl1,max.level=2)
Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots
 ..@ data       :'data.frame':    4 obs. of  2 variables:
 ..@ lines      :List of 4
 ..@ bbox       : num [1:2, 1:2] 448617 4630059 450088 4631874
 .. ..- attr(*, "dimnames")=List of 2
 ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots

with
> f...@data
 CodLin Comment
0      1    <NA>
1      2    <NA>
2      3    <NA>
3      4    <NA>

I can subset the data frame either as
> f...@data[1,]
 CodLin Comment
0      1    <NA>

or as

> f...@data["0",]
 CodLin Comment
0      1    <NA>

but for the  SLDF,  while  I  can use
> plot(fl1[1,])
I cannot use:
> plot(fl1["0",])
Error: trying to get slot "Lines" from an object of a basic class ("NULL") with no slots

So what would be the way of subsetting by IDs?

Also, Roger advised to get the IDs through either
> sapply(slot(fl1, "lines"), function(x) slot(x, "ID"))
[1] "0" "1" "2" "3"
or
> rownames(as.data.frame(fl1))
[1] "0" "1" "2" "3"

Considering that getting the IDs is an important task, would not
be appropriate having an specific function, as in the case of coordinates()?
For example,  ID(fl1) would be a lot easier to remember.

(I know I can do that function for my personal use, but then you end up not using standard R)

Thanks!

Agus



begin:vcard
fn:Agustin Lobo
n:Lobo;Agustin
org:Institut de Ciencies de la Terra "Jaume Almera" CSIC
adr:;;Lluis Sole Sabris s/n;Barcelona;;08028;Spain
email;internet:agustin.l...@ija.csic.es
url:http://www.ija.csic.es/gt/obster
version:2.1
end:vcard

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to