sf (version 0.2-8)

dplyr: Dplyr verb methods for sf objects

Description

Dplyr verb methods for sf objects

Usage

filter_.sf(.data, ..., .dots)
arrange_.sf(.data, ..., .dots)
distinct_.sf(.data, ..., .dots, .keep_all = FALSE)
group_by_.sf(.data, ..., .dots, add = FALSE)
mutate_.sf(.data, ..., .dots)
transmute_.sf(.data, ..., .dots)
select_.sf(.data, ..., .dots = NULL)
rename_.sf(.data, ..., .dots)
slice_.sf(.data, ..., .dots)
summarise_.sf(.data, ..., .dots)
gather_.sf(data, key_col, value_col, gather_cols, na.rm = FALSE, convert = FALSE, factor_key = FALSE)
spread_.sf(data, key_col, value_col, fill = NA, convert = FALSE, drop = TRUE, sep = NULL)

Arguments

.data
data object of class sf
...
other arguments
.dots
see corresponding function in package dplyr
.keep_all
see corresponding function in dplyr
add
see corresponding function in dplyr
data
see original function docs
key_col
see original function docs
value_col
see original function docs
gather_cols
see original function docs
na.rm
see original function docs
convert
see original function docs
factor_key
see original function docs
fill
see original function docs
drop
see original function docs
sep
see original function docs

Examples

Run this code
library(dplyr)
nc = st_read(system.file("shape/nc.shp", package="sf"))
nc %>% filter(AREA > .1) %>% plot()
# plot 10 smallest counties in grey:
nc %>% plot()
nc %>% arrange(AREA) %>% slice(1:10) %>% plot(add = TRUE, col = 'grey')
title("the ten counties with smallest area")
nc[c(1:100,1:10),] %>% distinct() %>% nrow()
nc$area_cl = cut(nc$AREA, c(0, .1, .12, .15, .25))
nc %>% group_by(area_cl) %>% class()
nc2 <- nc %>% mutate(area10 = AREA/10)
nc %>% transmute(AREA = AREA/10, geometry = geometry) %>% class()
nc %>% transmute(AREA = AREA/10) %>% class()
nc %>% select(SID74, SID79) %>% names()
nc %>% select(SID74, SID79, geometry) %>% names()
nc %>% select(SID74, SID79) %>% class()
nc %>% select(SID74, SID79, geometry) %>% class()
nc2 <- nc %>% rename(area = AREA)
nc %>% slice(1:2)
nc$area_cl = cut(nc$AREA, c(0, .1, .12, .15, .25))
nc.g <- nc %>% group_by(area_cl)
nc.g %>% summarise(mean(AREA))
nc.g %>% summarize(mean(AREA))
nc.g %>% summarize(mean(AREA)) %>% plot(col = grey(3:6 / 7))
library(tidyr)
nc %>% select(SID74, SID79, geometry) %>% gather(VAR, SID, -geometry) %>% summary()
library(tidyr)
nc$row = 1:100 # needed for spread to work
nc %>% select(SID74, SID79, geometry, row) %>% 
     gather(VAR, SID, -geometry, -row) %>% 
	spread(VAR, SID) %>% head()

Run the code above in your browser using DataCamp Workspace