R Guides

This page lists every R tutorial on Statology.

Import & Export Data
How to Manually Enter Raw Data in R
How to Save and Load RDA Files in R
How to Import CSV Files into R
How to Read a CSV from URL into R
How to Import Excel Files into R
How to Import TSV Files into R
How to Import SAS Files into R
How to Import SPSS Files into R
How to Import .dta Files into R
How to Export a Data Frame to CSV File in R
How to Export a Data Frame to Excel File in R
How to Export Data Frames to Multiple Excel Sheets in R
How to Export Multiple Plots to PDF in R
How to Use colClasses to Quickly Import Data in R
How to Use read.delim in R
How to Use write.table in R
How to Use setwd / getwd in R
How to Rename Files in R
How to Clear the Environment in R
How to Create a Multi-Line Comment in R

Descriptive Statistics
A Complete Guide to the Iris Dataset in R
How to Create Summary Tables in R
How to Calculate Five Number Summary in R
How to Calculate Summary Statistics by Group in R
How to Turn Off Scientific Notation in R
How to Calculate Z-Scores in R
How to Calculate Polychoric Correlation in R
How to Calculate Partial Correlation in R
How to Calculate Point-Biserial Correlation in R
How to Calculate Cross Correlation in R
How to Calculate Spearman Rank Correlation in R
How to Calculate Intraclass Correlation Coefficient in R
How to Calculate Correlation Between Multiple Variables in R
How to Create a Covariance Matrix in R
How to Calculate Variance in R
How to Remove Outliers in R
How to Calculate the Standard Error of the Mean in R
How to Calculate a Trimmed Mean in R
How to Calculate Conditional Mean in R
How to Calculate a Bootstrap Standard Error in R
How to Find Unique Values in a Column in R
How to Perform a COUNTIF Function in R
How to Perform a SUMIF Function in R
How to Use match Function in R
How to Use the View Function in R
How to Use table Function in R
How to Use sum Function in R
How to Use par Function in R
How to Use prop.table Function in R
How to Use aggregate Function in R
How to Use nrow Function in R
How to Use the gsub Function in R
How to Use the summary Function in R
How to Use colMeans Function in R
How to Use rowMeans Function in R
How to Average Across Columns in R
How to Sum Specific Columns in R
How to Sum Columns Based on a Condition in R
How to Calculate the Mean of Multiple Columns in R
How to Calculate the Mean by Group in R
How to Calculate the Sum by Group in R
How to Calculate Mean in R
How to Calculate Mode in R
How to Calculate a Weighted Mean in R
How to Calculate Geometric Mean in R
How to Calculate Cumulative Sums in R
How to Calculate Expected Value in R
How to Use seq Function in R
How to Use dist Function in R
How to Use diff Function in R
How to Calculate Conditional Probability in R
How to Apply Bayes’ Theorem in R
How to Calculate the Dot Product in R
How to Calculate Cosine Similarity in R
How to Calculate Euclidean Distance in R
How to Calculate Hamming Distance in R
How to Calculate Levenshtein Distance in R
How to Calculate Manhattan Distance in R
How to Calculate Minkowski Distance in R
How to Calculate Mahalanobis Distance in R
How to Calculate Jaccard Similarity in R
How to Calculate Combinations & Permutations in R
How to Calculate Autocorrelation in R
How to Calculate Rolling Correlation in R
How to Create Frequency Tables in R
How to Create a Frequency Table of Multiple Variables in R
How to Create Relative Frequency Tables in R
How to Create a Two Way Table in R
How to Find the Range in R
How to Calculate Interquartile Range in R
How to Use Min and Max Functions in R
How to Calculate Skewness & Kurtosis in R
How to Use the quantile() Function in R
How to Calculate Quartiles in R
How to Calculate Deciles in R
How to Calculate Percentiles in R
How to Calculate Quantiles by Group in R
How to Perform Bootstrapping in R
How to Calculate Point Estimates in R
How to Find Confidence Intervals in R
How to Calculate a Binomial Confidence Interval in R
How to Create a Contingency Table in R
How to Aggregate Multiple Columns in R
How to Create Pivot Tables in R
How to Count Number of Occurrences in Columns in R
How to Count Number of Rows in R
How to Perform Matrix Multiplication in R
How to Create the Identity Matrix in R
How to Perform Element-Wise Multiplication in R
How to Perform Univariate Analysis in R
How to Perform Bivariate Analysis in R
How to Calculate Cronbach’s Alpha in R
How to Calculate AUC (Area Under Curve) in R
How to Calculate F1 Score in R
How to Find the Antilog of Values in R
How to Solve a System of Equations in R

Visualizations
How to Plot Multiple Boxplots in One Chart in R
How to Create a Strip Chart in R
How to Plot Multiple Lines in One Chart in R
How to Plot Multiple Histograms in R
How to Plot Categorical Data in R
How to Create a Lollipop Chart in R
How to Create Kernel Density Plots in R
How to Create a Frequency Polygon in R
How to Use the Jitter Function in R for Scatterplots
How to Label Points on a Scatterplot in R
How to Create a Population Pyramid in R
How to Create 3D Plots in R
How to Use abline() in R
How to Create a Relative Frequency Histogram in R
How to Create a Histogram of Two Variables in R
How to Change Number of Bins in Histogram in R
How to Specify Histogram Breaks in R
How to Display Percentages on Histogram in R
How to Create a Scatterplot with a Regression Line in R
How to Create a Scatterplot in R with Multiple Variables
How to Plot Predicted Values in R
How to Plot Line of Best Fit in R
How to Use lm() Function in R to Fit Linear Models
How to Create and Interpret Pairs Plots in R
How to Plot a Confidence Interval in R
How to Plot Multiple Columns in R
How to Overlay Plots in R
How to Remove Outliers in Boxplots in R
How to Create Horizontal Boxplots in R
How to Create Radar Charts in R
How to Create a Stacked Barplot in R
How to Create a Grouped Barplot in R
How to Create a Stacked Dot Plot in R
How to Create Added Variable Plots in R
How to Draw a Legend Outside of a Plot in R
How to Create an Interaction Plot in R
How to Create a Pareto Chart in R
How to Create a Scree Plot in R
How to Create a Bland-Altman Plot in R
How to Plot a Logistic Regression Curve in R
How to Create a Forest Plot in R
How to Create a Log-Log Plot in R
How to Change Axis Scales in R Plots
How to Change Axis Intervals in R Plots
How to Add Error Bars to Charts in R
How to Use xlim() and ylim() in R
Curve Fitting in R
How to Use Italic Font in R
How to Change Font Size in Base R Plots

Probability Distributions
How to Use the Uniform Distribution in R
How to Use the Multinomial Distribution in R
How to Use the Triangular Distribution in R
How to Fit a Gamma Distribution to a Dataset in R
A Guide to dnorm, pnorm, rnorm, and qnorm in R
A Guide to dbinom, pbinom, qbinom, and rbinom in R
A Guide to dpois, ppois, qpois, and rpois in R
A Guide to dgeom, pgeom, qgeom, and rgeom in R
A Guide to dgamma, pgamma, qgamma, and rgamma in R
A Guide to dt, qt, pt, & rt in R
How to Calculate & Plot a CDF in R
How to Calculate Sampling Distributions in R
How to Apply the Empirical Rule in R
How to Use the Normal CDF in R
How to Plot a Normal Distribution in R
How to Plot a Chi-Square Distribution in R
How to Plot a t Distribution in R
How to Plot a Log Normal Distribution in R
How to Plot an Exponential Distribution in R
How to Plot a Binomial Distribution in R
How to Plot a Poisson Distribution in R
How to Plot a Weibull Distribution in R
How to Plot a Beta Distribution in R
How to Plot a Uniform Distribution in R
How to Calculate the P-Value of an F-Statistic in R
How to Calculate the P-Value of a Chi-Square Statistic in R
How to Calculate the P-Value of a T-Score in R
How to Calculate the P-Value of a Z-Score in R
How to Find the F Critical Value in R
How to Find the Chi-Square Critical Value in R
How to Find t Critical Values in R
How to Find Z Critical Values in R

Sampling Methods
Stratified Sampling in R
Cluster Sampling in R
Systematic Sampling in R

Hypothesis Tests
The Complete Guide: Hypothesis Testing in R
How to Conduct a Sobel Test in R
How to Perform a One Proportion Z-Test in R
How to Perform One Sample & Two Sample Z-Tests in R
How to Conduct Fisher’s Exact Test in R
How to Conduct a Jarque-Bera Test in R
How to Conduct an Anderson-Darling Test in R
A Guide to Bartlett’s Test of Sphericity
How to Calculate Standard Deviation in R
How to Calculate Pooled Standard Deviation in R
How to Calculate Weighted Standard Deviation in R
How to Calculate Standard Deviation of Data Frame Columns in R
How to Calculate the Coefficient of Variation in R
How to Identify Influential Data Points Using Cook’s Distance
How to Conduct Levene’s Test for Equality of Variances in R
How to Perform an F-Test in R
How to Create & Interpret a Q-Q Plot in R
How to Perform a Paired t-test in R
How to Perform Welch’s t-Test in R
How to Perform the Wilcoxon Signed-Rank Test in R
How to Calculate Pooled Variance in R
How to Perform a Mann-Whitney U Test in R
How to Perform a Mann-Kendall Trend Test in R
How to Perform McNemar’s Test in R
How to Perform Grubbs’ Test in R
How to Perform a Binomial Test in R
How to Perform Mood’s Median Test in R
How to Perform Runs Test in R
How to Test for Normality in R
How to Perform Multivariate Normality Tests in R
How to Perform a Shapiro-Wilk Test in R
How to Perform a Kolmogorov-Smirnov Test in R
How to Perform a Correlation Test in R
How to Perform a Chi-Square Test of Independence in R
How to Perform a Chi-Square Goodness of Fit Test in R
How to Perform a Likelihood Ratio Test in R
How to Calculate Cramer’s V in R
How to Calculate a Phi Coefficient in R
How to Perform a Chow Test in R
How to Perform a Granger-Causality Test in R
How to Perform Bartlett’s Test in R
How to Perform a Log Rank Test in R

Regression
How to Perform Cross Validation for Model Performance in R
How to Create a Prediction Interval for Linear Regression in R
How to Predict a Single Value Using a Regression Model in R
How to Perform Multiple Linear Regression in R
How to Perform Quadratic Regression in R
How to Perform Exponential Regression in R
How to Perform Logarithmic Regression in R
How to Perform Power Regression in R
How to Perform Robust Regression in R
How to Perform Quantile Regression in R
How to Perform Polynomial Regression in R
How to Plot a Polynomial Regression Curve in R
How to Perform Stepwise Regression in R
How to Perform Piecewise Regression in R
How to Perform Weighted Least Squares Regression in R
How to Interpret Regression Output in R
How to Interpret Pr(>|t|) in Regression Output in R
How to Calculate Variance Inflation Factor (VIF) in R
How to Perform Poisson Regression in R
How to Use the predict function with glm in R
The Difference Between glm and lm in R
How to Interpret glm Output in R
How to Perform a Durbin-Watson Test in R
How to Perform a Breusch-Godfrey Test in R
How to Perform a Breusch-Pagan Test in R
How to Perform White’s Test in R
How to Perform the Goldfeld-Quandt Test in R
How to Create a Residual Plot in R
How to Calculate Residual Standard Error in R
How to Perform a Box-Cox Transformation in R
How to Find Coefficient of Determination (R-Squared) in R
How to Calculate Adjusted R-Squared in R
How to Calculate BIC in R
How to Interpret a Scale-Location Plot in R
How to Interpret Diagnostic Plots in R
How to Calculate Studentized Residuals in R
How to Calculate Standardized Residuals in R
How to Calculate Leverage Statistics in R
How to Calculate DFFITS in R
How to Calculate DFBETAS in R
How to Calculate Mallows’ Cp in R
How to Calculate AIC in R
How to Plot Multiple Linear Regression Results in R
How to Calculate Residual Sum of Squares in R
How to Create a Histogram of Residuals in R
How to Create Dummy Variables in R
How to Add a Regression Equation to a Plot in R
How to Perform a Lack of Fit Test in R
How to Calculate SST, SSR, and SSE in R
How to Create a Confusion Matrix in R

ANOVA
How to Conduct a One-Way ANOVA in R
How to Conduct a Two-Way ANOVA in R
How to Conduct a Repeated Measures ANOVA in R
How to Conduct a Nested ANOVA in R
How to Conduct a MANOVA in R
How to Conduct an ANCOVA in R
How to Perform Welch’s ANOVA in R
How to Perform the Friedman Test in R
How to Perform Tukey’s Test in R
How to Perform a Brown–Forsythe Test in R
How to Perform a Bonferroni Correction in R
How to Perform Scheffe’s Test in R
How to Perform Dunnett’s Test in R
How to Perform Dunn’s Test in R
How to Perform Post-Hoc Pairwise Comparisons in R
How to Calculate Eta Squared in R
How to Create an Interaction Plot in R

Time Series
How to Calculate MAPE in R
How to Calculate SMAPE in R
How to Calculate RMSE in R
How to Calculate MSE in R
How to Calculate MAD in R
How to Calculate MAE in R
How to Plot a Time Series in R
How to Perform Naive Forecasting in R
How to Perform Lowess Smoothing in R
How to Calculate an Exponential Moving Average in R
How to Aggregate Daily Data to Monthly and Yearly in R
How to Extract Year from Date in R
How to Find Day of the Week in R
How to Subset by a Date Range in R
How to Use Date Formats in R
How to Perform an Augmented Dickey-Fuller Test in R

R Operations
A Guide to apply(), lapply(), sapply(), and tapply() in R
How to Add an Index (numeric ID) Column to a Data Frame in R
How to Add Superscripts & Subscripts to Plots in R
How to Check Data Type in R
How to Rename Data Frame Columns in R
How to Rename Factor Levels in R
How to Generate a Sample Using the Sample Function in R
How to Use the replicate() Function in R
How to Normalize Data in R
How to Standardize Data in R
How to Merge Data Frames Based on Multiple Columns in R
How to Merge Multiple Data Frames in R
Interpreting Errors in R: ‘max’ not meaningful for factors
How to Handle “undefined columns selected” in R
How to Remove Rows with Some or All NAs in R
How to Remove Multiple Rows in R
How to Select Rows Where Value Appears in Any Column in R
How to Select Rows by Condition in R
How to Drop Columns from Data Frame in R
How to Select Specific Columns in R
How to Select Columns by Index in R
How to Remove Specific Elements from Vector in R
R: How to Drop Rows that Contain a Specific String
How to Convert Strings to Lowercase in R
How to Concatenate Strings in R
Comparing grep() vs. grepl() in R
Comparing lapply() vs. sapply() in R
How to Print All Rows of a Tibble in R
How to Switch Two Columns in R
How to Remove Outliers from Multiple Columns in R
How to Stack Data Frame Columns in R
How to Split a Data Frame in R
How to Combine Two Columns into One in R
How to Combine Two Data Frames in R with Different Columns
How to Loop Through Column Names in R
How to Use “NOT IN” Operator in R
How to Subset a Data Frame in R
How to Compare Two Vectors in R
How to Combine Two Vectors in R
How to Compare Two Columns in R
How to Delete Multiple Columns in R
How to Interpolate Missing Values in R
How to Find and Count Missing Values in R
How to Impute Missing Values in R
How to Use na.omit in R
How to Use na.rm in R
How to Use is.na in R
How to Remove NA Values from Vector in R
How to Use complete.cases in R
How to Use “Is Not NA” in R
How to Transform Data in R
How to Perform Arcsine Transformation in R
How to Round Numbers in R
How to Transpose a Data Frame in R
How to Create an Empty Data Frame in R
How to Create an Empty Matrix in R
How to Create an Empty List in R
How to Create an Empty Vector in R
How to Add an Empty Column to a Data Frame in R
How to Append Rows to a Data Frame in R
How to Remove Rows in R
How to Remove Rows with NA in One Column in R
How to Remove Duplicate Rows in R
How to Append Values to a Vector Using a Loop in R
How to Append Values to List in R
How to Combine Lists in R
How to Delete Data Frames in R
How to Perform a VLOOKUP (Similar to Excel) in R
How to Remove Dollar Signs in R
How to Create Tables in R
How to Create a Nested For Loop in R
How to Create a For Loop with Range in R
How to Select Random Samples in R
How to Generate a Normal Distribution in R
How to Use xtabs() in R to Calculate Frequencies
How to Calculate Difference Between Rows in R
How to Retrieve Row Numbers in R
How to Apply Function to Each Row in R
How to Conditionally Remove Rows in R
How to Use rowSums() Function in R
How to Use colSums() Function in R
How to Sort a Data Frame by Date in R
How to Sort Values Alphabetically in R
How to Sort by Multiple Columns in R
How to Subset Lists in R
How to Convert List to Data Frame in R
How to Convert List to Vector in R
How to Convert List to Matrix in R
How to Convert Data Frame Column to Vector in R
How to Convert Matrix to Vector in R
How to Convert Character to Numeric in R
How to Convert Character to Factor in R
How to Convert Character to a Timestamp in R
How to Convert Factor to Character in R
How to Convert Factor to Date in R
How to Convert Factor to Numeric in R
How to Convert a Vector to String in R
How to Convert Strings to Dates in R
How to Convert String to Datetime in R
How to Convert Numbers to Dates in R
How to Convert Date to Numeric in R
How to Convert Numeric to Character in R
How to Convert Categorical Variables to Numeric in R
How to Create a Matrix from Vectors in R
How to Interpret Significance Codes in R
How to Change Row Names in R
How to Center Data in R
How to Sum Specific Rows in R
How to Write a Nested If Else Statement in R
How to Use cbind in R
How to Use rbind in R
How to Add a Column to a Data Frame in R
How to Add Column to Data Frame in R Based on Other Columns
How to Do a Left Join in R
How to Use the Which Function in R
How to Use the Square Root Function in R
How to Calculate Log in R
How to Sort a Data Frame by Column in R
How to Find the Max Value Across Multiple Columns in R
How to Use str_replace in R
How to Use str_split in R
How to Replace NAs with Strings in R
How to Split Column Into Multiple Columns in R
How to Replace Values in Data Frame in R
How to Replace Values in Data Frame Conditionally in R
How to Use setdiff in R
How to Use the droplevels Function in R
How to Reorder Factor Levels in R
Format Numbers as Percentages in R
Partial String Matching in R
How to Create Categorical Variables in R

How to Fix Common Errors
How to Fix: ‘x’ must be numeric
How to Fix: subscript out of bounds
How to Fix: Unexpected String Constant
How to Fix: NAs Introduced by Coercion
How to Fix: replacement has length zero
How to Fix: could not find function “%>%”
How to Fix: could not find function “ggplot”
How to Fix: plot.new has not been called yet
How to Fix: incorrect number of dimensions
How to Fix: error in select unused arguments
How to Fix: cannot change working directory
How to Fix: invalid factor level, NA generated
How to Fix: glm.fit: algorithm did not converge
How to Fix: dim(X) must have a positive length
How to Fix: not defined because of singularities
How to Fix: names do not match previous names
How to Fix: invalid model formula in ExtractVars
How to Fix: $ operator is invalid for atomic vectors
How to Fix: missing value where true/false needed
How to Fix: object of type ‘closure’ is not subsettable
How to Fix: incorrect number of subscripts on matrix
How to Fix: error: `mapping` must be created by `aes()`
How to Fix: non-numeric argument to binary operator
How to Fix: there are aliased coefficients in the model
How to Fix: Arguments imply differing number of rows
How to Fix: Discrete value supplied to continuous scale
How to Fix: error in plot.new() : figure margins too large
How to Fix: (list) object cannot be coerced to type ‘double’
How to Fix: no non-missing arguments to min; returning Inf
How to Fix: argument is not numeric or logical: returning na
How to Fix: Error in plot.window(…) : need finite ‘xlim’ values
How to Fix: error in file(file, “rt”) : cannot open the connection
How to Fix: prediction from a rank-deficient fit may be misleading
How to Fix: glm.fit: fitted probabilities numerically 0 or 1 occurred
How to Fix: aesthetics must be either length 1 or the same as the data
How to Fix: longer object length is not a multiple of shorter object length
How to Fix: contrasts can be applied only to factors with 2 or more levels
How to Fix: error in xy.coords(x, y, xlabel, ylabel, log) :’x’ and ‘y’ lengths differ
How to Fix: error in do_one(nmeth) : na/nan/inf in foreign function call (arg 1)
How to Fix: the condition has length > 1 and only the first element will be used
How to Fix: randomForest.default(m, y, …) : Na/NaN/Inf in foreign function call
How to Fix: number of items to replace is not a multiple of replacement length
How to Fix: error: ‘\u’ used without hex digits in character string starting “‘c:\u”


The Tidyverse

The tidyverse is a collection of R packages specifically designed for data science. The following tutorials explain how to use various functions in these packages.

dplyr – A package designed for manipulating data.
How to Arrange Rows Using dplyr
How to Remove Rows Using dplyr
How to Remove Columns Using dplyr
How to Add Columns Using dplyr
How to Count Observations by Group Using dplyr
How to Count Distinct Values Using dplyr
How to Create a Crosstab Using dplyr
How to Filter Rows Using dplyr
How to Filter by Multiple Conditions Using dplyr
How to Use a “not in” Filter in dplyr
How to Remove Rows with NA Values Using dplyr
How to Recode Values Using dplyr
How to Reorder Columns Using dplyr
How to Rename Column by Index Position Using dplyr
How to Group & Summarize Data Using dplyr
How to Find Maximum Value by Group Using dplyr
How to Replace NA with Zero Using dplyr
How to Join Multiple Data Frames Using dplyr
How to Use anti_join in dplyr
How to Use case_when in dplyr
How to Use bind_rows and bind_cols in dplyr
How to Select Columns by Index Using dplyr
How to Calculate Relative Frequencies Using dplyr
How to Create a Frequency Table by Group Using dplyr
How to Select the First Row by Group Using dplyr
How to Rank Variables by Group Using dplyr
How Use Mutate in dplyr
How to Use Conditional Mutate in dplyr

tidyr – A package designed for creating tidy data.
How to use the spread() function
How to use the gather() function
How to use the separate() function
How to use the unite() function

ggplot2 – A package designed for visualizing data.
A Complete Guide to the Best ggplot2 Themes
The Complete Guide to ggplot2 Titles
How to Change Background Color in ggplot2
How to Use a Transparent Background in ggplot2
How to Draw a Trend Line in ggplot2
How to Plot Two Lines in ggplot2
How to Change Font Size in ggplot2
How to Change the Legend Title in ggplot2
How to Change Legend Size in ggplot2
How to Change Legend Position in ggplot2
How to Change Legend Labels in ggplot2
How to Remove a Legend in ggplot2
How to Create a Manual Legend in ggplot2
How to Change Order of Items in ggplot2 Legend
How to Create Side-by-Side Plots in ggplot2
How to Set Axis Limits in ggplot2
How to Create a Bump Chart in R Using ggplot2
How to Create a Gantt Chart in R Using ggplot2
How to Create a Heatmap in R Using ggplot2
How to Overlay Density Plots in ggplot2
How to Make Pie Charts in ggplot2
How to Create a Grouped Boxplot in R Using ggplot2
How to Create Side-by-Side Boxplots in R
How to Create a Barplot in ggplot2 with Multiple Variables
How to Order the Bars in a ggplot2 Bar Chart
How to Plot a Linear Regression Line in ggplot2
How to Plot a Regression Line by Group with ggplot2
How to Add a Vertical Line to a Plot Using ggplot2
How to Add a Horizontal Line to a Plot Using ggplot2
How to Create a Log Scale in ggplot2
How to Create Smooth Lines in ggplot2
How to Plot a ROC Curve Using ggplot2
How to Assign Colors by Factor in ggplot2
How to Adjust Line Thickness in ggplot2
How to Use facet_wrap in ggplot2
How to Remove Gridlines in ggplot2
How to Remove Axis Labels in ggplot2
How to Rotate Axis Labels in ggplot2
How to Modify the Margins in ggplot2
How to Set Axis Breaks in ggplot2
How to Set Axis Label Position in ggplot2