liveBook · Manning

As.data.frame() function

As explained in Statistics Slam Dunk

The as.data.frame() function in R converts an object into a data frame when a suitable coercion method exists.

Use as.data.frame() when an object needs to become a classic R data frame. This is especially useful when older or base R code cannot read a tibble. section 13.6.2 section 10.3

The conversion can help when:

  • A base R workflow requires a data frame rather than a tibble. section 13.6.2
  • Printed results should display fully instead of using tibble’s limited screen output or scientific notation. section 13.6.2 section 10.3

Prepare win-share data for Lorenz curves

After reshaping and selecting the needed columns, convert the tibble and verify its class: ws9194 <- as.data.frame(ws9194) class(ws9194) ## [1] "data.frame" The resulting data frame can then supply columns to a base R for loop that creates four Lorenz curves. section 13.6.2

Display salary summaries clearly

Convert a summarized salary tibble at print time: print(as.data.frame(mean_salaries_real)) The output shows the average salaries for s2017 through s2000 as ordinary decimal values rather than scientific notation. section 10.3

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates assignment, class verification, and practical compatibility benefits, but does not explain coercion methods beyond tibble conversion.
Examples
Uses ws9194 for Lorenz curves and mean_salaries_real for readable salary-summary output.
What it assumes
Assumes familiarity with tibbles and basic data manipulation, while demonstrating the conversion and verification steps directly.
What you can do after
Apply it via base R to convert a tibble, verify the resulting class, and support incompatible plotting or printing workflows.
How it connects
Connects tibbles and data frames with base R plotting, Lorenz curves, salary summaries, and scientific notation.

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.