This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rstudio:subset_data [2013/04/03 15:59]
rstudio:subset_data [2016/05/13 20:45] (current)
Line 32: Line 32:
 </​code>​ </​code>​
 +{{ :​rstudio:​grepl.png?​direct&​300 |grepl}}
 +Notice that this is pulling out rows that have bike route, bike path, and bike lane, because we were greping on the word “bike.” This is a slightly stupid example, because we could have done this just using ''​subset'',​
 +<code r>
 +subset(labike,​ type != "​none"​)
 +{{ :​rstudio:​subsetvgrepl.png?​direct&​300 |subset versus grepl}}
 +The difference here is that with the first example, I was searching for all the responses that had the word "​bike"​ in them, and with ''​subset()''​ I'm picking the responses that are //not// equal to ''​none''​ because I know all the others have the word "​bike"​ in them. ''​grepl()''​ could be used for much more complex subsetting based on text, for example pulling out the word "​finally!"​ from thousands of tweets that contain tons of other text. In that case, there would not be an equivalent way to do the same thing using ''​subset()''​. ​
 +==== Spatial Subsetting ====
 +To do spatial subsetting (i.e. choose points for a subset by selecting them on a map), see [[rstudio:​Make_maps#​spatial_subsetting|spatial subsetting]].