Complete Example"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Whenever I start working on a dataset, I need to take a glance at the data to see how the data are or if the format is the one that I am expecting. I found myself coding similar lines over and over again with each data set I put my hands on. I decided to put that lines together in an R package so I and others can use them. I called it glancedata.

There are some already cool R packages to summarize information. Two of the best, in my opinion, are skimr and GGally. In this vignette, I provide examples of the functions in glancedata as well as some of the functions in these two packages.

Below is a table with the functions shown in this vignette.

library(dplyr)

pkg_list <- list(

    ## skim
  c(
    pkg = "`skimr`",
    fnct = "`skim`",
    des = "Alternative to `summary`. Friendly with `dplyr::group_by()`."
  ),

  ## glance_data
  c(
    pkg = "`glancedata`",
    fnct = "`glance_data`",
    des = "Alternative to `summary`. Emphasizes missing data and binary variables."
  ),

  ## glance_data_in_workbook
  c(
    pkg = "`glancedata`",
    fnct = "`glance_data_in_workbook`",
    des = "Similar to `glance_data`. Creates list of dataframes instead and saves XLSX file."
  ),

  ## plot_numerical_vars
  c(
    pkg = "`glancedata`",
    fnct = "`plot_numerical_vars`",
    des = "Creates a plot per numerical variable. It might be histogram, density plot, qqplot, violin plot or scatterplot."
  )
,

  ## plot_discrete_vars
  c(
    pkg = "`glancedata`",
    fnct = "`plot_discrete_vars`",
    des = "Creates a plot per variable with up to 20 different values. This limit can be adjusted.."
  )
,

  ## ggpairs
  c(
    pkg = "`GGally`",
    fnct = "`ggpairs`",
    des = "Creates plots for pairwise comparison of columns."
  )
) ## End list


pkg_list %>%
  purrr::map_df(~ tibble(Package = .x[1], 
                         Function = .x[2], 
                         Description = .x[3])) %>%
  knitr::kable()

Example (USArrests)

I am going to use a built-in dataset in R. I added some columns to it so you we can see what happens with different type of columns. You may load your own dataset instead of sample_data.

The example we are going to use is USArrests, which contains statistics, in arrests per 100,000 residents for assault, murder, and rape in each of the 50 US states in 1973. Also given is the percent of the population living in urban areas, according to the data set description (type help("USArrests") in the console to see more details).

library(dplyr)
library(tidyr)
library(knitr)

sample_data <- 
  tibble(State = state.name,
         Region = state.region) %>%
  bind_cols(as_tibble(state.x77)) %>%
  bind_cols(USArrests)

kable(head(sample_data))

Use of skimr

There are many packages useful

## Load package
library(skimr)

## Call main function
skim(sample_data)
library(glancedata)
library(dplyr)
library(tidyr)
library(knitr)
library(skimr)

skim(sample_data)

glance_data

library(glancedata)

glance_data(sample_data)

glance_data_in_workbook

library(glancedata)

glance_data_in_workbook(sample_data)

Testing a date mode

library(readr)
library(dplyr)

## Read data with dates from FiveThirtyEight
polls <- 
  read_csv("https://github.com/fivethirtyeight/data/tree/master/polls") 

Future versions



Try the glancedata package in your browser

Any scripts or data that you put into this service are public.

glancedata documentation built on Dec. 1, 2019, 1:22 a.m.