Appendix A Online: How do I …
The book’s GitHub repository includes a searchable version of this appendix of key tasks covered in the book, including sample code for some tasks as well as the chapter listings. Look for the file HowDoI.html if you downloaded the repo to your local system, or head to https://smach.github.io/R4JournalismBook/HowDoI.html.
Tasks and chapter(s) where they were covered
Add a CSS stylesheet to an R Markdown document’s YAML header, 15
Add a linear regression line to a ggplot2 visualization, 12
Add a pre-built theme to an R Markdown document’s YAML header, 15
Add a total column to a data frame, 14
Add a total row to a data frame, 14
Add address search to a leaflet map, 11
Add comments to code, 6
Add data to a geospatial object, 11
Add or subtract days, weeks, or years from a date, 13
Add or subtract months from a date, 10, 13
Add some randomness to a ggplot2 scatter plot so points don’t cover up other points, 9
Apply a function to a data frame by group, 8
Apply a function to all items in a data frame by column or row, 15
Apply a function to all items in a vector or list and return a character vector, 7
Apply a function to all items in a vector or list and return a data frame, 7
Apply a function to all items in a vector or list and return a numeric vector, 7
Apply a function to all items in a vector or list when you don’t want to store the output, 15
Apply a function to two vectors in parallel, 16
Assign a character string to a variable, 2
Assign a numerical value to a variable, 2
Calculate candidate vote percent by row, 12
Calculate correlations, 12
Categorize values into intervals, 10
Change or set the projections of an sf geospatial object, 11
Change the names of an R object, 3
Change the width of your RStudio console, 11
Change the working directory, 7
Check a URL path to see if scrapers are allowed, 16
Check for NA values, 8
Check for values that are not NA, 8
Check if a column or vector is numeric, 5
Check if a file exists in the current directory, 7
Check if running a function produces expected output, 10
Check if some values appear in another vector, 7
Clean column names to remove spaces and other problem characters, 4
Combine objects by columns, 3
Combine objects by rows, 3
Convert data files from one format to another without loading them into memory, 4
Convert numbers that came in as strings with commas to R numbers, 4
Copy a file to another directory, 7
Count the number of columns in a data frame, 4
Count the number of rows in a data frame, 4
Create a “wide” data frame from a narrow, “tidy” data frame, 14
Create a bar chart in base R, 6
Create a boxplot in base R, 6
Create a character vector, 2
Create a data frame, 4
Create a data frame with character string columns instead of factors, 4
Create a date object from a character string, 13
Create a grouped column chart with ggplot2, 6
Create a histogram in base R, 6
Create a line chart in base R, 6
Create a narrow “tidy” data frame from a “wide” data frame, 14
Create a numerical vector, 2
Create a plot with full ggplot2, 6
Create a scatter plot with linear regression, 17
Create a searchable, sortable HTML table in 1 line of code, 12
Create a special data frame class of tibble, 4
Create an interactive scatter plot with a linear regression, 17
Create an R Markdown document, 15
Create an Rstudio navigation section header from a comment, 6
Create basic data visualizations in base R, 6
Create multiple graphs by category in ggplot2, 9
Create multiple graphs by category with geo-appropriate grid placement, 9
Create quick plots with ggplot2, 6
Delete a data frame column, 8
Delete an R object you no longer need, 4
Display a fraction between 0 and 1 as a percentage, 15
Display code in an R Markdown document without running it, 15
Download a binary file, 11
Download a GitHub repository, 5
Download a remote data file to your local system, 4
Download U.S. Census data and geospatial files together, 11
Edit the R system environment, 11
Extract data from a PDF, 14
Extract link text from an HTML page, 16
Extract links from an HTML page, 16
Extract portion of an HTML page, 16
Extract the file name from a URL, 16
Filter a data frame by row number(s), 11
Find both the minimum and maximum values in a column or vector, 5
Find intersecting items in two vectors, 11
Find the current RStudio project’s home directory, 7
Find the day of week for a date object, 13
Find the difference between 2 dates, 13
Find the location of minimum or maximum values in a column or vector, 5
Find the minimum or maximum value in a column or vector, 5
Find the next item for each item in a vector, 13
Find the previous value of each item in a vector, 13
Find the top ranked item(s) in a data frame, 14
Find the top vote-getter in each row of a data frame, 12
Generate a sequence of dates, 10, 13
Generate a vector of 1:length(myvec), 16
Generate an HTML document from an R Markdown document, 15
geocode addresses, 11
Get a count of items in each group in a data frame, 8
Get a count of items in each group in a vector, 8
Get a U.S. Census API key, 11
Get help for a function, 2
Get help for a package, 2
Get the current date, 10
Get the first of the month of a date object, 10, 13
Import a shapefile into R, 11
Import a shapefile into R as a simple features object, 11
Import a shapefile into R as a simple features object and see projection info, 11
Import a specific range of cells from a spreadsheet, 14
Import an HTML table into R, 4
Import data files into R, 4
Import U.S. Census shapefiles directly into R without manually downloading them first, 11
Install a package from CRAN, 2, 5
Install a package from GitHub, 4
Join (concatenate) 2 strings to be one, 9, 10, 11
Knit (render, or generate) an R Markdown document with parameters, 15
Load a package into your working session’s memory, installing it if it doesn’t already exist, 3, 5
Load a saved R object, 4
Map colors to categories in ggplot2 bar or column charts, 9
Map colors to categories in ggplot2 scatter plots, 9
Merge 2 data frames by a common column in each, 8
Open the RStudio snippets file, 6
Pipe the results of one statement into the next, 5
Quickly plot an imported shapefile with tmap, 11
Read an HTML page into R, 16
Re-draw the most recent tmap map, 11
Remove a package from the current working session, 13
Remove empty data frame columns, 12
Remove groupings after dplyr::group_by(), 13
Remove leading and trailing white spaces, 8
Remove the name of a named value, 8
Remove x-axis text in ggplot2, 9
Rename a data frame column, 6
Reorder x axis based on y axis in ggplot2, 6
Repeat a number or character string n times, 4
Replace characters in a string, 11
Represent a value that isn’t available, 8
Rotate ggplot2 x-axis text 45 degrees, 9
Run a function on data by group and summarize the results, 8
Run a package’s demo code, 6
Run R code from an external file, 3
Run R code in an R Markdown document without displaying the code, 15
Save an interactive tmap map to an HTML page, 11
Save an R object, 4
Save an R object to optimize for speed, compression, or Python compatibility, 4
See a demo of base R visualizations, 6
See a statistical summary of a data frame, 5
See all available base R demo code on your system, 6
See all available built-in colors, 6
See all available methods for an R object, 4
See all available package code demos on your system, 6
See all files in the current directory, 7
See all the unique values in a vector, 7
See available data sets from all installed packages, 4
See basic structure of a data frame, 5
See both row and column names of a data frame, 5
See both the number of rows and columns in a data frame, 5
See more information about a data set, 4
See names of an R object, 3,4
See RStudio keyboard shortcuts, 2
Create my own RStudio keyboard shortcuts, 2, 18
See the current working directory, 7
See the first 6 rows of a data frame, 5
See the last 6 rows of a data frame, 5
See the value of item number n in a list, 7
Select a column by number, 5
Select a row by number, 5
Select columns by exact name, 4
Select columns by pattern in a name, 14
Select multiple columns by number, 5
Select multiple rows by number, 5
Select only numeric columns in a data frame, 5
Select rows based on a condition, 5
Select the top n rows of a data frame based on colx, 6
Set tmap view mode to interactive or static, 11
Set up and use variables, or parameters in an R Markdown document, 15
Sort a data frame by one column, descending values, 5
Sort a vector in base R in descending order, 6
Suppress R warnings or messages when running code in an R Markdown document, 15
Test if one value equals another, 5
Test if two R objects are identical, 5
Toggle tmap views, 11
Turn a column of numbers into character strings, 5
Turn a column or vector into numbers, 5
Turn a vector of character strings into a single string, 14
Turn off scientific notation, 9
Unzip a zipped file, 11
Use a formula (anonymous function) with purrr’s map or walk, 15
Use a function from an external package without loading, 3
Use a key-value pair from a named lookup vector, 8
Use regular expressions in R, 17
Write a vectorized if-else statement, 10
Write an if statement, 10
Write an if statement with multiple conditions without using if() functions, 10
Write an if-else statement, 10
Write an RStudio code snippet, 6
Write your own function, 10
Write tests to check whether your function works as expected, 10
Check if any (at least one) items in a vector match a condition, 13