g1 <- st_sfc(st_point(1:2), st_point(c(5, 8)), st_point(c(2, 9)))
x1 <- st_sftime(a = 1:3, geometry = g1, time = Sys.time())
g2 <- st_sfc(st_point(c(4, 6)), st_point(c(4, 6)), st_point(c(4, 6)))
x2 <- st_sftime(a = 2:4, geometry = g2, time = Sys.time())
library(dplyr)
## inner_join
inner_join(x1, as.data.frame(x2), by = "a") # note: the active time column is
# time.x and the active geometry column geometry.x
inner_join(x2, as.data.frame(x1), by = "a")
## left_join
left_join(x1, as.data.frame(x2), by = "a")
left_join(x2, as.data.frame(x1), by = "a")
## right_join
right_join(x1, as.data.frame(x2), by = "a")
right_join(x2, as.data.frame(x1), by = "a")
## full_join
full_join(x1, as.data.frame(x2), by = "a")
full_join(x2, as.data.frame(x1), by = "a")
## semi_join
semi_join(x1, as.data.frame(x2), by = "a")
semi_join(x2, as.data.frame(x1), by = "a")
## anti_join
anti_join(x1, as.data.frame(x2), by = "a")
anti_join(x2, as.data.frame(x1), by = "a")
## filter
filter(x1, a <= 2)
## arrange
arrange(x1, dplyr::desc(a))
## group_by
group_by(x1, time)
## ungroup
ungroup(group_by(x1, time))
## rowwise
x1 %>%
mutate(a1 = 5:7) %>%
rowwise() %>%
mutate(a2 = mean(a, a1))
## mutate
x1 %>%
mutate(a1 = 5:7)
## transmute
x1 %>%
transmute(a1 = 5:7)
## select
x1 %>%
select(-time) %>%
select(geometry)
## rename
x1 %>%
rename(a1 = a)
## slice
x1 %>%
slice(1:2)
## summarise
x1 %>%
summarise(time = mean(time))
x1 %>%
summarize(time = mean(time))
## distinct
x1 %>%
distinct(geometry)
## gather
library(tidyr)
x1 %>%
mutate(a1 = 5:7) %>%
gather(key = "variable", value = "value", a, a1)
## pivot_longer
x1 %>%
mutate(a1 = 5:7) %>%
pivot_longer(cols = c("a", "a1"), names_to = "variable", values_to = "value")
## spread
x1 %>%
mutate(a1 = 5:7) %>%
gather(key = "variable", value = "value", a, a1) %>%
spread(key = "variable", value = "value")
## sample_n
set.seed(234)
x1 %>%
sample_n(size = 10, replace = TRUE)
## sample_frac
x1 %>%
sample_frac(size = 10, replace = TRUE) %>%
sample_frac(size = 0.1, replace = FALSE)
## nest
x1 %>%
nest(a1 = -time)
## unnest
x1 %>%
mutate(a1 = list(1, c(1, 2), 5)) %>%
unnest(a1)
## separate
x1 %>%
mutate(x = c(NA, "a.b", "a.d")) %>%
separate(x, c("A", "B"))
## unite
x1 %>%
mutate(x = c(NA, "a.b", "a.d")) %>%
separate(x, c("A", "B")) %>%
unite(x, c("A", "B"))
## separate_rows
x1 %>%
mutate(z = c("1", "2,3,4", "5,6")) %>%
separate_rows(z, convert = TRUE)
## drop_na
x1 %>%
mutate(z = c(1, 2, NA)) %>%
drop_na(z)
x1 %>%
mutate(z = c(1, NA, NA)) %>%
drop_na(z)
x1 %>%
mutate(time = replace(time, 1, NA)) %>%
drop_na(time)
Run the code above in your browser using DataLab