Code:
library(dplyr)
group_by_if(ggplot2::diamonds, is.factor) %>%
count()
Output:
Code:
library(dplyr)
group_by_if(ggplot2::diamonds, is.factor) %>%
count()
Output:
Code:
library(dplyr)
filter_if(iris, is.numeric, all_vars(.>2.4))
Output:
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 6.3 3.3 6.0 2.5 virginica
2 7.2 3.6 6.1 2.5 virginica
Code:
library(dplyr)
mtcars %>%
mutate(efficiency_group = ntile(mpg, 5)) %>%
head()
Output:
Code:
library(dplyr)
BOD
Output:
Time demand
1 1 8.3
2 2 10.3
Adding a month on with a '+' is fairly straightforward.
Code:
library(lubridate)
ymd("2018-01-01") + months(1)
Output:
[1] "2018-02-01"
Code:
library(lubridate)
my_date <- ymd("2018-11-23")
rollback(my_date)
Output:
[1] "2018-10-31"
Code:
library(tidyr)
library(tibble)
df <- data_frame(animal = c("cat", "dog"), toy = c("ball", "stick"), total = c(5, 6))
df
Output:
# A tibble: 2 x 3
Code:
library(tidyr)
library(dplyr)
test_scores <- data_frame(student = c("Amy", "Belle", "Candice"),
score = c("75-81-86", "77-70-82", "90-91-91"))
test_scores
Output:
Code:
str(starwars)
Output:
# Lots of output up here
...
..$ : chr
..$ : chr