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 Read Specific Rows from CSV File into R
How to Import & Merge Multiple CSV Files in R
How to Import CSV with Column Names that Contain Spaces in R
How to Download Files from the Internet Using R
How to Use readLines Function in R
How to Read Zip Files into R
How to List Files by Date in R
How to Use list.files() in R
How to Use file.choose() in R
How to Use fread() in R
How to Open an .R File in RStudio
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 List to a File in 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 write.xlsx in R
How to Use read.table in R
How to Use setwd / getwd in R
How to Use the sink() Function in R
How to Use file.path() Function in R
How to Save R Output to Text File
How to Check if File Exists in R
How to Rename Files in R
How to Delete a File in R
How to Move a File in R
How to Clear the Environment in R
How to Unload a Package in R
How to Check which Package Version is Loaded in R
How to Create a Multi-Line Comment in R
The Difference Between require() and library() in R
How to Load Multiple Packages in R
How to Check if a Package is Installed in R
How to Check if a Directory Exists in R

Descriptive Statistics
How to Calculate Descriptive Statistics in R
A Complete Guide to the Iris Dataset in R
A Complete Guide to the mtcars Dataset in R
A Complete Guide to the Boston Dataset in R
A Complete Guide to the diamonds Dataset in R
How to Perform Data Cleaning 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 Calculate Correlation By Group in R
How to Calculate Percentage by Group in R
How to Perform Exploratory Data Analysis in R
How to Calculate Ratios 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 Matthews Correlation Coefficient in R
How to Calculate Intraclass Correlation Coefficient in R
How to Find the P-value of Correlation Coefficient in R
How to Calculate Correlation Between Multiple Variables in R
How to Calculate Correlation in R with Missing Values
How to Create a Correlation Matrix 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 the Median Value of Rows in R
How to Calculate a Cumulative Average in R
How to Calculate a Bootstrap Standard Error in R
How to Perform Data Binning in R
How to Calculate Cohen’s d in R
How to Calculate Cohen’s Kappa in R
How to Select Unique Rows in a Data Frame in R
How to Select All But One Column in R
How to Find Unique Values in a Column in R
How to Find Unique Values and Sort Them in R
How to Find Unique Rows Across Multiple Columns in R
How to Add Multiple Columns to Data Frame in R
How to Perform a COUNTIF Function in R
How to Perform a SUMIF Function in R
How to Print String and Variable on Same Line in R
How to Use paste & paste0 Functions in R
The Difference Between cat() and paste() in R
How to Use do.call in R
How to Use set.seed in R
How to Use the coeftest() Function in R
How to Use the confint() Function in R
How to Use the linearHypothesis() Function in R
How to Use unlist() Function in R
How to Use length() Function in R
How to Use lines() Function in R
How to Use fitdistr() Function in R
How to Use the drop() Function in R
How to Use the intersect() Function in R
How to Use the identical() Function in R
How to Use attach() Function in R
How to Use nchar() Function in R
How to Use dim() Function in R
How to Use str() Function in R
How to Use cor() Function in R
How to Use optim Function in R
How to Use the melt() Function in R
How to Use the get() Function in R
How to Use the cat() Function in R
How to Use strsplit() Function in R
How to Use substring() Function in R
How to Use the c() Function in R
How to Use text() Function in R
How to Use sign() Function in R
How to Use mtext() Function in R
How to Use the assign() Function in R
How to Use sprintf Function in R
How to Use the source Function in R
How to Use match Function in R
How to Use split Function in R
How to Use tabulate Function in R
How to Use the scale 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 microbenchmark() in R
How to Use prop.table Function in R
How to Use aggregate Function in R
How to Use aggregate & Not Drop Rows with NA in R
How to Use nrow Function in R
How to Use ncol Function in R
How to Find the Size of a Data Frame in R
How to Use the gsub Function in R
How to Use the sub 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 Use pmax & pmin Functions 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 a Column in R
How to Calculate the Mean of Multiple Columns in R
How to Calculate Standard Deviation by Group 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 Mode by Group 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 Cumulative Sum by Group 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 Use with() and within() Functions 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 a Cross Product in R
How to Calculate Cosine Similarity in R
How to Calculate Bray-Curtis Dissimilarity 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 Find Unique Combinations of Two Vectors 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 Create a Three Way Table in R
How to Sort a 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 Calculate Percentile Rank in R
How to Convert Between Z-Scores and Percentiles 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 Calculate Confidence Interval for Regression Coefficient in R
How to Calculate Standardized Regression Coefficients 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 Use pivot_longer() on All Columns in R
How to Use pivot_wider() with Multiple Columns in R
How to Reshape Data Between Wide and Long Format in R
How to Count TRUE Values in Logical Vector in R
How to Count Number of Occurrences in Columns in R
How to Count Number of Rows in R
How to Count Number of Elements in List in R
How to Count Unique Values by Group in R
How to Count Unique Values in Column in R
How to Count Values in Column with Condition in R
How to Group By and Count with Condition in R
How to Add a Count Column to a Data Frame 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
How to Plot an Equation in R
How to Perform Linear Interpolation in R

Visualizations
How to Plot Multiple Boxplots in One Chart in R
How to Plot Boxplots with Mean Values in R
How to Change Axis Labels of Boxplot in R
How to Add Titles to Plots in Base R
How to Create a Strip Chart in R
How to Create an Ogive Graph in R
How to Plot Distribution of Column Values in R
How to Plot Multiple Lines in One Chart in R
How to Plot Multiple Histograms in R
How to Add Vertical Line to Histogram in R
How to Plot Categorical Data in R
How to Create a Correlation Heatmap in R
How to Use pheatmap() to Create Heatmaps 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 Create a Biplot in R
How to Plot a Function Curve in R
How to Label Points on a Scatterplot in R
How to Create a Scatterplot Matrix in R
How to Plot a Table in R
How to Plot a Subset of a Data Frame in R
How to Create a Population Pyramid in R
How to Plot SVM Object in R
How to Create 3D Plots in R
How to Use abline() in R
How to Add Label to abline in R
How to Plot Multiple Plots on Same Graph in R
How to Create a Histogram with Different Colors 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 Scatter Plots by Group 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 Predict Values in R Using Multiple Regression Model
How to Perform Linear Regression with Categorical Variables in R
How to Perform t-Test for Slope of Regression Line in R
How to Plot Predicted Values in R
How to Plot Line of Best Fit in R
How to Plot a Decision Tree in R
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 Overlay Normal Curve on Histogram in R
How to Reorder Boxplots 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 Change Legend Size in Base R Plot
How to Add Text Outside of a Plot in R
How to Use cex to Change the Size of Plot Elements in R
How to Use bty Option to Change Chart Box Styles in R
How to Draw Circles in Plots in R
How to Change Legend Position in Base R Plots
How to Create a Horizontal Legend in Base R
How to Create an Interaction Plot in R
How to Create a Pareto Chart in R
How to Create a Bubble 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 Use Bold 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 Calculate KL Divergence in R
How to Fit a Gamma Distribution to a Dataset in R
Normal Distribution in R: dnorm, pnorm, rnorm, qnorm
Binomial Distribution in R: dbinom, pbinom, qbinom, rbinom
Poisson Distribution in R: dpois, ppois, qpois,  rpois
Chi-Square Distribution in R: dchisq, pchisq, qchisq, and rchisq
Geometric Distribution in R: dgeom, pgeom, qgeom, rgeom
Gamma Distribution in R: dgamma, pgamma, qgamma, rgamma
The t Distribution in R: dt, qt, pt, rt
The Difference Between rnorm() and runif() 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 Apply the Central Limit Theorem in R
How to Use the Normal CDF in R
How to Simulate & Plot a Bivariate Normal Distribution 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
How to Perform a Wald Test in R
How to Perform a KPSS Test in R
How to Perform a Kruskal-Wallis Test in R
How to Perform a Variance Ratio 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 Standard Deviation of Data Frame Rows 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 One Sample t-test in R
How to Perform a Two Sample t-test 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 Cramer-Von Mises 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 Calculate Gini 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 LOESS 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 Spline 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 Interpret Pr(>|z|) in Logistic Regression Output in R
How to Calculate Odds Ratios in Logistic Regression Model in R
How to Calculate Variance Inflation Factor (VIF) in R
How to Use Method of Least Squares in R
How to Use trainControl() to Control Training Parameters in R
How to Perform Poisson Regression in R
How to Extract Regression Coefficients from glm in R
How to Use the predict Function with glm in R
How to Use the predict Function with lm in R
How to Use the predict Function with Logistic Regression in R
The Difference Between glm and lm in R
How to Interpret glm Output in R
How to Use lm() Function in R to Fit Linear Models
How to Extract P-Values from lm() Function in R
How to Extract Coefficients from lm() Function in R
How to Extract R-Squared from lm() Function in R
How to Extract Residuals from lm() Function in R
How to Extract Standard Errors from lm() Function in R
How to Extract RMSE from lm() Function in R
How to Use Subset of Data Frame with lm() Function in R
How to Use regsubsets() in R for Model Selection
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 Create Partial Residual Plots in R
How to Calculate Residual Standard Error in R
How to Calculate Robust Standard Errors in R
How to Test for Multicollinearity in R
How to Perform a Box-Cox Transformation in R
How to Calculate R-Squared for glm in R
How to Calculate 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 Use stepAIC in R for Feature Selection
How to Plot lm() Results 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 OLS Regression 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
How to Use the Elbow Method 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 Three-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 Fisher’s LSD 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
When to Use aov() vs. anova() in R

Time Series
How to Calculate MAPE in R
How to Calculate SMAPE in R
How to Calculate WMAPE 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 Fit a TBATS Model in R
How to Create a Time Series in R
How to Plot a Time Series in R
How to Convert Data Frame to Time Series in R
How to Perform Naive Forecasting in R
How to Perform Lowess Smoothing in R
How to Calculate a Rolling Average in R
How to Calculate a Moving Average by Group in R
How to Calculate an Exponential Moving Average in R
How to Aggregate Daily Data to Monthly and Yearly in R
How to Calculate Number of Months Between Dates in R
How to Find Earliest Date in a Column in R
How to Extract Month from Date in R
How to Add and Subtract Months from a Date in R
How to Subtract Hours from Time in R
How to Add Days to Date in R
How to Calculate Business Days in R
How to Extract Year from Date in R
How to Convert Excel Date Format to Proper Date in R
How to Get Week Number from Dates in R
How to Find Day of the Week in R
How to Group Data by Week in R
How to Group Data by Month in R
How to Group Data by Hour in R
How to Convert Date to Quarter and Year in R
How to Subset by a Date Range in R
How to Use Date Formats in R
How to Use as.Date() Function in R
How to Perform an Augmented Dickey-Fuller Test in R
How to Get First or Last Day of Month Using Lubridate in R
How to Convert Character to Date Using Lubridate in R
How to Generate a Sequence of Dates Using lubridate 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
Difference Between data.table vs. data frame in R
How to Filter a data.table in R
How to Filter Rows where Column is Between Two Values in R
How to Use dcast Function from data.table in R
How to Set Data Frame Column as Index in R
How to Rename Data Frame Columns in R
How to Rename a Single Column in R
How to Rename Factor Levels in R
How to Add New Level to Factor in R
How to Subset Data Frame by Multiple Conditions in R
How to Subset Data Frame by Factor Levels in R
How to Subset Data Frame by List of Values in R
How to Perform Reverse Coding in R
How to Rename an Object in R
How to Use the names Function in R
How to Use make.names Function in R
How to Use setNames Function in R
How to Generate a Sample Using the Sample Function in R
How to Replicate Rows in Data Frame in R
How to Use the cut() Function in R
How to Use rep() Function in R
How to Use the replicate() Function in R
How to Use the replace() Function in R
How to Use the sweep() Function in R
How to Use the tapply() Function in R
How to Use the map() Function in R
How to Use gsub() in R
How to Use strptime and strftime Functions in R
How to Use difftime() in R
How to Perform Quantile Normalization in R
How to Normalize Data in R
How to Standardize Data in R
How to Scale Values Between 0 and 1 in R
How to Perform Multidimensional Scaling in R
How to Use SMOTE for Imbalanced Data in R
How to Merge Data Frames Based on Multiple Columns in R
How to Merge Data Frames by Column Names in R
How to Merge Multiple Data Frames in R
How to Merge Data Frames by Row Names 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 by Index in R
How to Select Rows Where Value Appears in Any Column in R
How to Select Rows with NA Values in R
How to Select Rows by Condition in R
How to Select Rows in Data Frame Based on Values in Vector in R
How to Extract Last Row in Data Frame in R
How to Check if Row in One Data Frame Exists in Another in R
How to Select Top N Values by Group in R
How to Drop Columns from Data Frame in R
How to Drop Columns by Name in R
How to Drop Columns if Name Contains Specific String in R
How to Drop All Columns Except Specific Ones in R
How to Remove Columns with NA Values in R
How to Use strsplit() with Multiple Delimiters in R
How to Count Number of NA Values in Each Column in R
How to Select Specific Columns in R
How to Select Columns by Index in R
How to Collapse Text by Group in Data Frame in R
How to Check if Column Contains String in R
How to Check if Column Exists in Data Frame in R
How to Check if Multiple Columns are Equal in R
How to Select Columns Containing a Specific String in R
How to Count Words in String in R
How to Remove Specific Elements from Vector in R
How to Filter a Vector in R
How to Check if a Vector Contains a Given Element in R
How to Split a Vector into Chunks in R
How to Drop Rows that Contain a Specific String in R
How to Split Character String and Get First Element in R
How to Check if Character is in String in R
How to Extract Numbers from Strings in R
How to Extract String Between Specific Characters in R
How to Extract String After Specific Character in R
How to Extract String Before Space in R
How to Extract Substring Starting from End of String in R
How to Check if String Contains Multiple Substrings in R
How to Convert Strings to Lowercase in R
How to Concatenate Strings in R
How to Concatenate Vector of Strings in R
How to Use grepl() with Multiple Patterns in R
Comparing grep() vs. grepl() in R
Comparing lapply() vs. sapply() in R
How to Use lapply() with Multiple Arguments in R
How to Print Tables in R
How to Print All Rows of a Tibble in R
How to Print Multiple Variables on the Same Line 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 Split Data into Equal Sized Groups in R
How to Combine Rows with Same Column Values in R
How to Combine Two Columns into One in R
How to Combine Two Data Frames in R with Different Columns
How to Add Suffix to Column Names in R
How to Add Prefix to Column Names in R
How to Loop Through Column Names in R
How to Get Column Names in R
How to Loop Through List in R
How to Use “OR” Operator in R
How to Use the Pipe Operator in R
How to Use “NOT IN” Operator in R
How to Use Dollar Sign ($) Operator in R
How to Use the Tilde Operator (~) in R
How to Subset a Data Frame in R
How to Keep Certain Columns in R
How to Extract Specific Columns from 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 Compare Strings in R
How to Compare Three Columns in R
How to Delete Multiple Columns in R
How to Perform Listwise Deletion in R
How to Interpolate Missing Values in R
How to Find and Count Missing Values in R
How to Count Non-NA Values in R
How to Impute Missing Values in R
How to Find Columns with All Missing Values in R
How to Find Column with Max Value for Each Row in R
How to Use drop_na 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 Use is.null in R
How to Remove NA Values from Vector in R
How to Remove NA from Matrix in R
How to Add New Column to Matrix in R
How to Use complete.cases in R
How to Use “Is Not NA” in R
How to Handle NaN Values 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 Remove Rows with Any Zeros in R
How to Remove Empty Rows from Data Frame in R
How to Check if Data Frame is Empty 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 Create an Empty Plot in R
How to Add Column If It Does Not Exist in R
How to Create New Data Frame from Existing Data Frame in R
How to Add Points to an Existing Plot in R
How to Clear All Plots in R
How to Extract Rows from 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 Count Duplicates in R
How to Remove Duplicate Rows in R
How to Remove Duplicate Rows so None are Left 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 Combine a List of Matrices 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 Table and Include NA Values in R
How to Create a Nested For Loop in R
How to Create a For Loop with Range in R
How to Write a Repeat Loop in R
How to Return Value from Function in R
How to Write a tryCatch() Function in R
How to Catch integer(0) in R
How to Create a Vector of Zeros in R
How to Select Random Samples in R
How to Generate Random Numbers in R
How to Create a Vector with Random Numbers in R
How to Create a Matrix with Random Numbers in R
How to Create a Data Frame with Random Numbers in R
How to Use runif Function 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 Calculate Odds Ratios in R
How to Add a Total Row to a Data Frame in R
How to Retrieve Row Numbers in R
How to Apply Function to Each Row in R
How to Find the Max Value in Each Row in R
How to Find Closest Value in Vector in R
How to Use apply() Function on Specific Columns in R
How to Remove First Row from Data Frame in R
How to Find First Row that Meets Criteria in R
How to Select First N Rows of Data Frame 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 Sort Using row.names in R
How to Sort a Matrix in R
How to Use sort(), order(), and rank() in R
How to Use ties.method in rank() Function in R
How to Create a List of Lists in R
How to Subset Lists in R
How to Use LETTERS in R
How to Find Location of Character in a String in R
How to Remove Characters from String in R
How to Remove Last Character from String in R
How to Remove Spaces from Strings in R
How to Remove Quotes from Strings in R
How to Convert Vector to List 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 Table to Matrix in R
How to Convert Table to Data Frame in R
How to Convert Tibble to Data Frame in R
How to Convert Data Frame Column to Vector in R
How to Convert Data Frame Column to List in R
How to Convert Data Frame to Matrix in R
How to Convert Matrix to Data Frame 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 UNIX Timestamp to Date 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 Datetime to Date 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 Numeric to Factor in R
How to Convert TRUE and FALSE to 1 and 0 in R
How to Convert Categorical Variables to Numeric in R
How to Create Categorical Variable from Continuous in R
How to Perform Label Encoding 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 Scale Only Numeric Columns in R
How to Sum Specific Rows in R
The Difference Between ifelse() vs. if_else() in R
How to Prevent ifelse() from Converting Date to Numeric in R
How to Use which() Function with Multiple Conditions in R
How to Use If Statement with Multiple Conditions in R
How to Write a Nested If Else Statement in R
How to Include NA in ifelse Statement in R
How to Write a Case Statement in R
How to Use cbind in R
How to Use rbind in R
How to Use rbindlist in R
How to Rename Columns When Using cbind 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 Do a Right Join in R
How to Do an Inner Join in R
How to Do an Outer Join in R
How to Do a Cross Join in R
The Difference Between merge() vs. join() in R
How to Perform Fuzzy Matching in R
How to Use the Which Function in R
How to Use the Square Root Function in R
How to Calculate the Square of a Value in R
How to Calculate Log in R
How to Calculate Lagged Values 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_c in R
How to Use str_count in R
How to Use str_replace in R
How to Use str_remove in R
How to Use str_pad in R
How to Use str_trim in R
How to Use str_sub in R
How to Use str_match in R
How to Use str_split in R
How to Use str_extract in R
How to Use str_detect in R
How to Replace Values in a Matrix in R
How to Replace NAs with Strings in R
How to Replace Zero with NA in R
How to Replace Inf Values with NA in R
How to Replace Blanks with NA in R
How to Replace Values in Data Frame in R
How to Replace Values in Data Frame Conditionally in R
How to Split Column Into Multiple Columns 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 Split Data into Training & Test Sets in R
How to Use createDataPartition() Function in R

How to Fix Common Errors
How to Suppress Warnings in R
How to Fix: object not found
How to Fix: ‘x’ must be numeric
How to Fix: subscript out of bounds
How to Fix: stat_bin() using bins = 30
How to Fix: unexpected ‘else’ in “else”
How to Fix in R: invalid graphics state
How to Fix: system is exactly singular
How to Fix: argument is of length zero
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: reached getOption(“max.print”)
How to Fix in R: invalid type (list) for variable
How to Fix: The following objects are masked
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: more columns than column names
How to Fix: glm.fit: algorithm did not converge
How to Fix: dim(X) must have a positive length
How to Fix: Error: Duplicate identifiers for rows
How to Fix: not defined because of singularities
How to Fix: replacement has X rows, data has Y
How to Fix: Error: attempt to apply non-function
How to Fix: names do not match previous names
How to Fix: invalid model formula in ExtractVars
How to Fix: Cannot add ggproto objects together
How to Fix: duplicate ‘row.names’ are not allowed
How to Fix Error in R: non-conformable arguments
How to Fix: $ operator is invalid for atomic vectors
How to Fix: missing value where true/false needed
How to Fix in R: ‘height’ must be a vector or a matrix
How to Fix: object of type ‘closure’ is not subsettable
How to Fix: incorrect number of subscripts on matrix
How to Fix: argument “no” is missing, with no default
How to Fix: error in rep(1, n) : invalid ‘times’ argument
How to Fix: Cannot use `+.gg()` with a single argument
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: invalid (do_set) left-hand side to assignment
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: incomplete final line found by readTableHeader
How to Fix: aggregate function missing, defaulting to ‘length’
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: error in lm.fit(x, y, offset = offset, …) : na/nan/inf in ‘y’
How to Fix: Error in eval(predvars, data, env) : object ‘x’ not found
How to Fix: prediction from a rank-deficient fit may be misleading
How to Fix: error in strsplit(unitspec, ” “) : non-character argument
How to Fix: Error in n() : This function should not be called directly
How to Fix: glm.fit: fitted probabilities numerically 0 or 1 occurred
How to Fix: Error in colMeans(x, na.rm = TRUE) : ‘x’ must be numeric
How to Fix: geom_path: Each group consists of only one observation
How to Fix: character string is not in a standard unambiguous format
How to Fix in R: Error in as.Date.numeric(x) : ‘origin’ must be supplied
How to Fix: Error in stripchart.default(x1, …) : invalid plotting method
How to Fix: aesthetics must be either length 1 or the same as the data
How to Fix: missing values are not allowed in subscripted assignments
How to Fix: aggregate.data.frame(): arguments must have same length
How to Fix: ggplot2 doesn’t know how to deal with data of class uneval
How to Fix: error in sort.int(x, na.last, decreasing, …) : ‘x’ must be atomic
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 FUN(newx[, i], …) : invalid ‘type’ (character) of argument
How to Fix: error in xy.coords(x, y, xlabel, ylabel, log) :’x’ and ‘y’ lengths differ
How to Fix: number of rows of result is not a multiple of vector length (arg 1)
How to Fix: error in do_one(nmeth) : na/nan/inf in foreign function call (arg 1)
How to Fix: `data` must be a data frame, or other object coercible by `fortify()`
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”
How to Fix: attempt to set ‘colnames’ on an object with less than two dimensions
How to Fix: Don’t know how to automatically pick scale for object of type function
How to Fix: error in rbind(deparse.level, …) : numbers of columns of arguments do not match


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 Arrange Rows by Group Using dplyr
How to Arrange Rows in Custom Order Using dplyr
How to Remove Rows Using dplyr
How to Remove Last Row in Data Frame Using dplyr
How to Remove Columns Using dplyr
How to Add Columns Using dplyr
How to Use ungroup() in dplyr
How to Round Values in Specific Columns Using dplyr
How to Transpose a Data Frame Using dplyr
How to Pass a String as Variable Name in dplyr
How to Apply Function to Each Row Using dplyr
How to Sum Across Multiple Columns Using dplyr
How to Count Observations by Group Using dplyr
How to Count Distinct Values Using dplyr
How to Calculate a Cumulative Sum Using dplyr
How to Create a Crosstab Using dplyr
How to Filter for Unique Values Using dplyr
How to Use %in% to Filter for Rows with Value in List in dplyr
How to Filter by Date Using dplyr
How to Filter Rows Using dplyr
How to Filter by Row Number Using dplyr
How to Filter by Multiple Conditions Using dplyr
How to Use a Conditional Filter in dplyr
How to Filter Data Frame without Losing NA Rows Using dplyr
How to Group By and Filter Data Using dplyr
How to Find Duplicate Elements Using dplyr
How to Use a “not in” Filter in dplyr
How to Remove Rows with NA Values Using dplyr
How to Join Data Frames on Multiple Columns Using dplyr
How to Perform Left Join Using Selected Columns in dplyr
How to Perform Left Join with Different Column Names in dplyr
How to Recode Values Using dplyr
How to Reorder Columns Using dplyr
How to Rename Multiple Columns Using dplyr
How to Rename Column by Index Position Using dplyr
How to Group by All But One Column in dplyr
How to Group & Summarize Data Using dplyr
How to Summarise Multiple Columns Using dplyr
How to Summarise Data But Keep All Columns Using dplyr
How to Calculate Summary Statistics Using dplyr
How to Calculate Standard Deviation Using dplyr
How to Find Maximum Value by Group Using dplyr
How to Calculate Mean for Multiple Columns Using dplyr
How to Replace NA with Zero Using dplyr
How to Replace NA with Mean Using dplyr
How to Replace NA with Median Using dplyr
How to Replace String in Column Using dplyr
How to Replace Multiple Values in Data Frame 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 Random Rows in R Using dplyr
How to Select Columns by Index Using dplyr
How to Select Columns by Name Using dplyr
How to Select Columns that Do Not Start with String in dplyr
How to Select Only Numeric Columns Using dplyr
How to Select Rows of Data Frame by Name 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 to Calculate Lag by Group Using dplyr
How to Convert Multiple Columns to Numeric Using dplyr
How to Convert Multiple Columns to Factor Using dplyr
How Use mutate() in dplyr
How to Use n() Function in dplyr
How to Remove First Character from Strings Using dplyr
How to Mutate Variable if Column Contains String in dplyr
How to Use select_if with Multiple Conditions in dplyr
How to Change Factor Levels Using mutate() in dplyr
How to Use mutate() with Multiple Conditions in dplyr
How to Use Conditional Mutate in dplyr
How to Use the slice() Function in dplyr
How to Use the relocate() Function in dplyr
How to Use the ntile() Function in dplyr
How to Use the across() Function in dplyr
How to Use the coalesce() Function in dplyr
How to Use the transmute() Function 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
How to use the pivot_wider() function
How to use the pivot_longer() function

ggplot2 – A package designed for visualizing data.
A Complete Guide to the Best ggplot2 Themes
A Complete Guide to the Default Colors in ggplot2
A Complete Guide to ggplot2 Titles
How to Use hjust & vjust to Move Elements in ggplot2
How to Change Title Position in ggplot2
How to Change Background Color in ggplot2
How to Use a Transparent Background in ggplot2
How to Add a Confidence Interval in ggplot2
How to Create a Q-Q Plot in ggplot2
How to Create a Residual Plot in ggplot2
How to Add Tables to Plots in ggplot2
How to Draw a Trend Line in ggplot2
How to Add an Average Line to Plot in ggplot2
How to Change Line Colors in ggplot2
How to Plot Two Lines in ggplot2
How to Jitter Points in ggplot2
How to Change Font Size in ggplot2
How to Change Fill and Border Color of Points in ggplot2
How to Change Point Size in ggplot2
How to Change Point Shape in ggplot2
How to Change Line Type in ggplot2
How to Add Horizontal Line to Plot and Legend 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 Plot Multiple Lines in ggplot2
How to Connect Points with Lines in ggplot2
How to Remove a Legend in ggplot2
How to Remove a Legend Title in ggplot2
How to Create a Manual Legend in ggplot2
How to Create a Legend with Multiple Rows in ggplot2
How to Change Order of Items in ggplot2 Legend
How to Change Spacing Between Legend Items in ggplot2
How to Add Text to ggplot2 Plots
How to Change X-Axis Labels in ggplot2
How to Group by Two Columns in ggplot2
How to Set the Number of Bins for a Histogram in ggplot2
How to Create Histograms by Group in ggplot2
How to Add Labels to Histogram in ggplot2
How to Create Side-by-Side Plots in ggplot2
How to Set Axis Limits in ggplot2
How to Use scale_x_continuous in ggplot2
How to Use scale_y_continuous in ggplot2
How to Convert Axis to Percentage Scale 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 Plot in ggplot2 Using Multiple Data Frames
How to Create a Grouped Boxplot in R Using ggplot2
How to Create Side-by-Side Boxplots in R
How to Create a Barplot with Multiple Variables in ggplot2
How to Order the Bars in a ggplot2 Bar Chart
How to Reorder Bars in a Stacked Bar Chart in ggplot2
How to Use stat=”identity” in ggplot2 Plots
How to Plot Mean with geom_bar() in ggplot2
How to Adjust Space Between Bars in ggplot2
How to Change Colors of Bars in Stacked Bart Chart in ggplot2
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 Plot Mean and Standard Deviation in ggplot2
How to Add Label to geom_vline in ggplot2
How to Add Label to geom_hline in ggplot2
How to Use geom_abline in ggplot2
How to Use alpha with geom_point() in 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 Plot Mean Line by Group in 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 Change Facet Axis Labels in ggplot2
How to Change the Order of Facets in ggplot2
How to Reverse Order of Axis in ggplot2
Difference Between facet_wrap and facet_grid in ggplot2
How to Remove NAs from Plot in ggplot2
How to Remove Gridlines in ggplot2
How to Draw Arrows in ggplot2
How to Shade an Area in ggplot2
How to Remove Axis Labels in ggplot2
How to Rotate Axis Labels in ggplot2
How to Rotate Annotated Text in ggplot2
How to Create a Violin Plot in ggplot2
How to Modify the Margins in ggplot2
How to Set Axis Breaks in ggplot2
How to Set Axis Label Position in ggplot2
How to Order Items on x-axis in ggplot2
How to Order Y-Axis Labels Alphabetically in ggplot2
How to Change Number of Axis Ticks in ggplot2
How to Add Caption to ggplot2 Plots
How to Add Subtitle in ggplot2
How to Add Footnote to ggplot2 Plots
How to Adjust Line Thickness in Boxplots in ggplot2
How to Label Outliers in Boxplots in ggplot2
How to Use ggsave() to Save ggplot2 Plots