CodeHurry R Learning Center

Welcome to the R Learning Center

R Programming Examples

About This Collection

Unlike the SAS course materials on CodeHurry, which are organized into structured lessons, this section provides a collection of R programming examples developed from prior data analysis projects. These examples demonstrate selected applications of R programming and practical coding approaches used in analytic tasks.

Programming Examples

Reading and Writing Data Files

Demonstrates how to import and export data in R using a variety of file formats, including SAS, text, CSV, Excel, and JSON files. Covers read.table(), read.csv(), read_excel(), fromJSON(), and save()/load() for creating and managing R data objects.

View Code

Datasets in R Packages

Demonstrates how to explore built-in datasets in R packages using data(), head(), class(), mode(), and typeof() to examine data structures and variable types.

View Code

Manipulating Data

Demonstrates basic data frame manipulation and exploratory data analysis in R. Extract variables and subsets, count missing and specific values, create frequency tables, and sort a data frame.

View Code

dplyr: filter(), group_by(), summarise() and knitr: kable()

Uses the dplyr package to filter observations, group data by selected classification variables, compute aggregate counts, and generate a formatted summary table. Uses knitr::kable() to create a Markdown-formatted table and write the output to a text file.

View Code

sapply() vs. lapply()

Demonstrates the difference between lapply() and sapply(). lapply() returns a list, while sapply() simplifies the result to a named vector, matrix, or array when possible.

View Code

Utility Tools

Demonstrates commonly used R utility functions, including dir.exists(), file.exists(), list.files(), rm(), and sink(), for managing files, directories, workspace objects, and output.

View Code
← Back to CodeHurry

Disclaimer

The R programming materials provided on this website are intended for educational and reference purposes only. The author assumes no responsibility for errors, omissions, or consequences resulting from the use of these materials. Users should independently verify program logic, analytical assumptions, and results before applying these examples to their own research or production analyses.

Trademark Notice

R® is a registered trademark of the R Foundation for Statistical Computing. CodeHurry is not affiliated with, endorsed by, or sponsored by the R Foundation for Statistical Computing. R-related programming examples on this website are provided solely for educational and reference purposes.