Split shapefile polygon according to the NAME_1 in R

If a polygon can not be sub-setted by its attributes, how can I split it according to the attributes in force?

chnshp<-getData('GADM', country="China", level=1)
chnshp  #     nfeatures   : 32 
row.names(chnshp) #  
chnshp$NAME_1  #   
chnshp$NAME_1=='Hainan' # Only one row is True
row.names(chnshp[chnshp$NAME_1=='Hainan'])  #   32 rows
chnshp[chnshp$NAME_1=='Hainan']    #     nfeatures   : 32 
plot(chnshp[chnshp$NAME_1=='Hainan'])  #   the entire China plot?


How to split it according to the column NAME_1?

Make sure that chnshp[chnshp$NAME_1=='Hainan'] return the Hainan area.


Use the "[" extraction function rather than "[[".

plot(chnshp[chnshp$NAME_1=='Hainan', ])

It makes more sense to send a logical vector of length 32 to "[" than to "[[" which is expecting a length one argument. (And it's probably better not to refer to these as 'attributes', since that is a term with particular meaning in R.

Need Your Help

term frequency of documents with Nest Elasticsearch

c# elasticsearch nest word-frequency

I am new in elasticsearch and want to get the top N term frequency of the "content" field of a specific document using Nest elasticsearch. I've searched a lot to find a proper answer that works for...

Passing this to an object within an object during the constructor call

c++ compiler-errors

I am trying to iron out my first compile in a long time, and I think this is the last hurdle.