**View:**

**Sorted by:**

### How to Use Regular Expressions in R

R supports the concept of regular expressions, which allows you to search for patterns inside text. You may never have heard of regular expressions, but you’re probably familiar with the broad concept. [more…]

### How to Create a Factor in R

To create a factor in R, you use the factor() function. The first three arguments of factor() warrant some exploration: [more…]

### How to Create a Function in R

To create a function in R, you will make and transform an R script. The best way to learn to swim is by jumping in the deep end, so let’s just write a function to show you how easy that is in R. [more…]

### How to Use a Function in R

Once you have created and transformed a script in R, save the script again, and load it into the console using the source() command displayed earlier. Now you see . . . nothing. R doesn’t let you know [more…]

### How to Reduce the Number of Lines in R

When transforming the script in R, not all elements are required. In fact, the return() statement is optional, because, by default, R will always return the value of the last line of code in the function [more…]

### How to Use Arguments When You Transform a Script in R

There are multiple ways to use arguments in R. Here are some ways you can specify arguments in a function call when transforming a script. [more…]

### How to Work with Files and Folders in R

You know how to import your data into R and export your data from R. Now all you need is an idea of where the files are stored with R and how to manipulate those files. Every R session has a default location [more…]

### How to Manipulate Files in R

Occasionally, you may want to write a script in R that will traverse a given folder and perform actions on all the data in the files or a subset of files in that folder. [more…]

### How to Compare Two Data Samples with R’s T-Test

If you want to use R’s t.test()function to compare your data, you first have to check, among other things, whether both samples are normally distributed. [more…]

### How to Compare Two Data Samples with R

R gives you two standard tests for comparing two groups with numerical data: the t-test with the t.test() function, and the Wilcoxon test with the wilcox.test [more…]

### How to Compare Paired Data with R

When testing differences between two data groups in R, you can have either paired or unpaired data. Paired data comes from experiments where two different treatments were given to the same subjects. [more…]

### How to Test Data Proportions with R

Let’s look at an example to illustrate the basic R tests for data proportions. The following example is based on real research, published by Robert Rutledge, MD, and his colleagues in the [more…]

### How to Analyze Data in Tables with R

You can use R’s prop.test()function for data in matrices and tables. For prop.test(), these tables need to have two columns with the number of counts for the two possible outcomes. [more…]

### How to Extract Data Test Results with R

Many tests in R return a htest object. That type of object is basically a list with all the information about the test that has been carried out. All these [more…]

### How to Analyze Data Variances in Models with R

An analysis of variance (ANOVA) is a very common technique used with R to compare the means between different groups of data. To illustrate this, take a look at the dataset [more…]

### How to Set the Contrasts for Your Data with R

Before you can use R’s aov()function with your data, you’d better set the *contrasts* you’re going to use. Contrasts are very often forgotten about when doing ANOVA [more…]

### How to Evaluate the Differences in Your Data with R

To check the data model that you created with ANOVA (analysis of variance), you can use R’s summary() function on the model object like this: [more…]

### How to Model Linear Data Relations with R

An analysis of variance for your data also can be written as a *linear model* in R, where you use a factor as a predictor variable to model a response variable. [more…]

### How to Evaluate Linear Data with R

Naturally, R provides a whole set of different tests and measures to evaluate how well your model fits your data as well as look at the model assumptions. Again, the overview presented here is far from [more…]

### How to Predict New Data Values with R

Apart from describing relations, models also can be used to predict values for new data. For that, many model systems in R use the same function, conveniently called [more…]

### How to Enter Data into the R Text Editor

Although R is primarily a programming language, R has a very basic data editor that allows you to enter data directly using the edit() function.

The edit [more…]

### How to Use the Clipboard to Copy and Paste Data in R

Another way of importing data interactively into R is to use the Clipboard to copy and paste data. To import data from the Clipboard, use the readClipboard [more…]

### How to Use read.csv() to Import Data in R

One of the easiest and most reliable ways of getting data into R is to use text files, in particular CSV (comma-separated values) files. The CSV file format uses commas to separate the different elements [more…]

### How to Use read.table() to Import Tabular Data in R

The functions read.csv(), read.csv2(), and read.delim() are special cases of the multipurpose read.table() function in R that can deal with a wide variety of data file formats. The [more…]

### How to Read Data from Excel into R

If you ask users of R what the best way is to import data directly from Microsoft Excel, most of them will probably answer that your best option is to first export from Excel to a CSV file and then use [more…]