liveBook · Manning

Glimpse() function

As explained in Statistics Slam Dunk

The glimpse() function is a dplyr function that displays a compact transposed summary of a tabular object, including its dimensions, columns, and value types.

glimpse() is a fast first look at a tabular object in R. Pass a data set as its lone argument to print its row and column counts, then a compact transposed preview: variables run vertically, with each variable’s class and sample values alongside it. This layout makes wide data easier to inspect in the console. section 2.3.3 section 3.3

Use glimpse() immediately after importing data and again after wrangling. It helps confirm that the expected columns survived, that filtering or selecting changed the dimensions as intended, and that conversions produced the intended types, such as factor or date. section 3.3 section 16.2

A glimpse output answers several practical questions at once:

  • How large is the data set? The header reports its rows and columns. section 8.3
  • What variables are available? Every remaining variable is listed from top to bottom. section 14.2.4
  • What type is each variable? Markers such as <dbl>, <int>, <chr>, <fct>, and <date> appear beside names. section 2.3.3 section 16.2
  • Do the values look plausible? A truncated run of values gives a quick content check before deeper analysis. section 19.2

Check a reduced NBA team data set

After creating O_PTS and retaining five team-level variables, call glimpse(nba). The output confirms 300 rows and 5 columns, shows that season is a factor, and lets you verify that O_PTS contains numeric values before modeling or plotting. section 14.2.4

glimpse() is not the only viewing option. dim() returns only row and column counts, while head() and tail() show the first or last observations in their usual, non-transposed layout. Pair them when the vertical glimpse display is less intuitive. section 2.3.3 section 3.3

glimpse(draft)
## Rows: 289
## Columns: 18
## $ Rk       <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1...
## $ Year     <fct> 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, ...
## $ Pk       <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1...
## $ Tm       <fct> LAC, MEM, OKC, SAC, MIN, MIN, GSW, NYK, TOR, MIL...
## $ Player   <chr> "Blake Griffin", "Hasheem Thabeet", "James Harde...
## $ Age      <dbl> 20.106, 22.135, 19.308, 19.284, 18.252, 20.144, ...
## $ Pos      <chr> "F", "C", "G", "G-F", "G", "G", "G", "C-F", "G-F...
## $ Born     <fct> us, tz, us, us, es, us, us, us, us, us, us, us, ...
## $ College  <chr> "Oklahoma", "UConn", "Arizona State", "Memphis",...
## $ From     <fct> 2011, 2010, 2010, 2010, 2012, 2010, 2010, 2010, ...
## $ To       <fct> 2020, 2014, 2020, 2019, 2020, 2012, 2020, 2017, ...
## $ G        <dbl> 622, 224, 826, 594, 555, 163, 699, 409, 813, 555...
## $ MP       <dbl> 34.8, 10.5, 34.3, 30.7, 30.9, 22.9, 34.3, 18.8, ...
## $ WS       <dbl> 75.2, 4.8, 133.3, 28.4, 36.4, -1.1, 103.2, 16.4,...
## $ WS48     <dbl> 0.167, 0.099, 0.226, 0.075, 0.102, -0.015, 0.207...
## $ Born2    <fct> USA, World, USA, USA, World, USA, USA, USA, USA,...
## $ College2 <fct> 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, ...
## $ Pos2     <chr> "F", "C", "G", "G-F", "G", "G", "G", "C-F", "G-F...

Inspect a draft-data glimpse to see dimensions, variable names, classes, and representative values in one console-friendly display. section 2.3.3

How Statistics Slam Dunk covers it

How deep it goes
Explains the transposed, truncated output and contrasts it with dim(), head(), and tail() without detailing its internal implementation.
Examples
Demonstrates draft, play-by-play, salary, player-salary, franchise, team, season-statistics, joined-game, and free-throw data outputs.
What it assumes
Assumes an imported tabular object and introduces inspection through a single data-set argument.
What you can do after
Apply it via dplyr to quickly verify a table’s dimensions, columns, classes, and representative values.
How it connects
Connects data inspection to read_csv(), dim(), head(), tail(), select(), filter(), as.factor(), and as.Date().

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.