Practical solutions

R Howtos How-To Guides

Solve the problem. Keep building. Collection of R how-to articles

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

How to Create Histogram With ggplot in RThis article introduces how to create a histogram with ggplot in R How to Create Custom Legend With ggplot in RThis article introduces how to create custom legend with ggplot in R How to Calculate the R-Squared Statistic in RThis article shows how to obtain the R-squared statistic in R from the summary of a linear regression model. It also shows how to calculate the R-squared statistic manually, both directly and by using a custom function. How to Export a Data Frame From R to Microsoft ExcelThis article shows how to export a data frame from R to Microsoft Excel using the write.csv() function and functions provided by other packages. It also addresses problems that may occur in opening CSV files. How to Install R Packages From SourceThis article shows how to use the install.packages() function to install R packages from source. It points out the two conditions that need to be met for the installation from source to be successful. How to Use Vectorized if Function With Multiple Conditions in RThis article shows how to use multiple conditions in the vectorized ifelse and if_else functions in creating or updating a column in a data frame. It also draws attention to the vectorized AND and OR operators. How to Pass Command Line Arguments to R CMD BATCH and RscriptThis article shows how to pass command line arguments to R CMD BATCH and Rscript, and how to save the output as a file. How to Remove User-Defined Objects From the Workspace in RThis article shows how to remove user-defined objects from the workspace in R using the rm() function and the Environment tab of R Studio. How to Uninstall R and All Its Packages on WindowsThis article shows how to uninstall R and all its packages on Windows. Uninstalling R only removes the original installation files. To remove the packages, we need to find the paths to the R library folders, uninstall packages using R Studio, uninstall R, and then delete the library folders. How to Find the Null Space of a Matrix in RThis article shows how to find the null space of a matrix in R using the nullspace function of the pracma package. How to Remove Object Names and Dimnames in RThis article shows how to remove the names and dimnames of objects and get only the values in R. Different approaches such as the unname() function, the as.vector() function, etc. are illustrated with examples. How to Set Location of Current File as Working Directory in R StudioThis article shows how to set the location or path of the current R script or Rmd file as the working directory in R Studio, without any user intervention or interaction. It shows three methods specific to R Studio and one more generally applicable. How to Generate a Regular Sequence of Numbers in RThis article shows how to easily generate a regular sequence of numbers in R using the colon operator and the seq() function. How to Convert Multiple Columns From Integer to Numeric Type in RThis article shows how to convert multiple columns from integer to a numeric type using a single command in R. The examples include base R and dplyr approaches to perform the conversion. How to Interpret Output of system.time Function in RThis article briefly explains what is being measured by the system.time function in R. It then provides simple examples to illustrate what each of the components user, system and elapsed are measuring in the output of the function. How to Customize the PCA Biplot in RThis article demonstrates how to customize the PCA biplot in R. Several defaults are modified to obtain a more useful visualization of the biplot. How to Use the if and if...else Statements in RThis article describes the syntax of if and if-else constructs of R, emphasizing the peculiarities. The code examples illustrate all the points provided. How to Compute Binomial Coefficients in JavaThis article demonstrates the use of two libraries to calculate binomial coefficients for large values of n. The example code shows the use of CERN's colt library and the Apache Commons Numbers library. How to Use the group_by Function in R DplyrThis article shows how to use the group_by() function from R's dplyr package to group rows for data analysis. It shows how we can combine group_by() with the summarize() or summarise(), filter() and mutate() functions to do the desired data analysis. How to Create and Visualize a Correlation Matrix in RThis article first shows how to prepare data to create a correlation matrix in R. It then demonstrates the use of the cor() function to create a correlation matrix, and the ggcorr() function from the GGally package to visualize it. How to Test for Normality of Data in RThis article demonstrates three techniques to assess the normality of ungrouped, univariate data in R. Visually, we can assess the normality using a histogram or a Q-Q plot. For a quantitative measure, we can use the popular Shapiro-Wilk test. How to Create and Interpret Dummy Variables in RThis article shows how to easily create dummy variables in R using the fastDummies package. It concludes with a section on how to interpret the dummy variables in a linear regression model. How to Use Cross-Validation for a KNN Classification Model in RThis article demonstrates how to use the caret package to build a KNN classification model in R using the repeated k-fold cross-validation technique. The train function also creates and tests models for different specified values of K neighbors and builds the model with the highest accuracy. How to Perform Logistic Regression in RThis tutorial demonstrates how to perform logistic regression in R.