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 Read a Text File Line by Line in RThis article shows how to process or read a plain text file line by line in R. 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 Use the Source Function to Run Another R ScriptThis article demonstrates how to use the source function of base R to run another R script which may be located in the same directory as the first script or in a different directory. It explains how and when to use the chdir argument to change R's working directory temporarily. 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 Perform K-Means Clustering in Base RThis article shows how to perform K-means clustering using base R functions. All steps, including the elbow bend plot to choose K, and the PCA scatter plot when there are more than two variables, are demonstrated in base R. 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. How to Concatenate Strings in RThis tutorial demonstrates how to concatenate strings in R. The fread() Function in RThis tutorial demonstrates how to use fread function in R. How to Perform Polynomial Regression in RThis tutorial demonstrates how to perform polynomial regression in R.