R Functions (W)

Note

This review/summary page provides an extensive list of R functions tailored for data wrangling tasks that we have used in this chapter. Each function is systematically described, highlighting its primary package source and its specific utility.

To learn more about these functions, readers can:

  1. Use R’s Built-in Help System: For each function, access its documentation by prefixing the function name with a question mark in the R console, e.g., ?as.factor. This displays the function’s manual page with descriptions, usage, and examples.

  2. Search Websites: Simply Google, or visit the CRAN website to search for specific function documentation. Websites like Stack Overflow and RStudio Community often have discussions related to R functions.

  3. Tutorials and Online Courses: Platforms like DataCamp, Coursera, and edX offer R courses that cover many functions in depth. Also there are examples of dedicated R tutorial websites that you might find useful. One example is “Introduction to R for health data analysis” by Ehsan Karim, An Hoang and Qu.

  4. Books: There are numerous R programming books, such as “R for Data Science” by Hadley Wickham and “The Art of R Programming” by Norman Matloff.

  5. Workshops and Webinars: Institutions and organizations occasionally offer R programming workshops or webinars.

Whenever in doubt, exploring existing resources can be highly beneficial.

Function_name Package_name Use
as.factor base Converts a variable to factors. `as.factor` is a wrapper for the `factor` function.
cbind base Merges matrices.
CreateTableOne tableone Creates a frequency table.
data.frame base Creates a dataset with both numeric and character variables. Requires unique column names and equal length for all variables.
dim base Returns the dimensions of a data frame (rows x columns).
filter dplyr Subsets a dataset by selecting a sub-population.
function base Used to define custom functions, e.g., for calculating standard deviation.
head base Displays the first six elements of an object (e.g., a dataset). `tail` displays the last six.
is.na base Checks for missing values in a variable.
levels base Displays the levels of a factor variable.
list base Stores vectors, matrices, or lists of differing types.
mode base Determines the type of a variable.
na.omit base/stats Removes all rows with missing values from a dataset.
names base Displays names of objects, e.g., variable names of a data frame.
nlevels base Shows the number of levels in a factor variable.
nrow base Returns the dimensions of a data frame. `nrow` gives row count and `ncol` gives column count.
plot base/graphics Draws scatter plots or line graphs.
print base Prints the output to console.
prop.table base Displays percentage summary for a table.
rbind base Appends matrices row-wise.
read.csv base/utils Reads data from a CSV file.
relevel base/stats Changes the reference group of a factor variable.
sasxport.get Hmisc Loads data in the SAS format.
save base Saves R objects, such as datasets.
select dplyr Selects specified variables from a dataset.
set.seed base Sets a seed for random number generation ensuring reproducibility.
str base/utils Displays the structure of a dataset, including data type of variables.
subset base, dplyr Subsets a dataset by selecting a sub-population.
summary base Provides a summary of an object, like variable statistics.
table base Displays frequency counts for a variable.
write.csv base/utils Saves a data frame to a CSV file in a specified directory.