**View:**

**Sorted by:**

### How to Change Lattice Plot Options in R

R has a very good reputation for being able to create publication-quality graphics, however if you want to use your lattice graphics in reports or documents, you’ll probably want to change the plot options [more…]

### How to Make Common Graphs with Lattice in R

While the lattice graphics package features a long list of graphic types in R, bar charts and box-and-whisker plots are among the most commonly used. [more…]

### How to Use Data in Tall Format in Lattice Plots in R

When you have data in tall format in R, you can easily use lattice graphics to visualize subgroups in your data. For instance, what happens when you want to analyze more than one variable simultaneously [more…]

### How to Configure R

Apart from accepting the options in the installation procedure for R, you can change a number of startup options by adapting the Rprofile.site file. This file is located inside the installation directory [more…]

### How to Install and Configure RStudio

RStudio is a relatively new and shiny editor for R. It’s easy to use, it has a decent Help page, it has very good support, and it incorporates R in a practical way. Of course, you’re free to work with [more…]

### How to Install and Load ggplot2 in R

Because ggplot2 isn’t part of the standard distribution of R, you have to download the package from CRAN and install it.

### How to Use Layers in ggplot2 in R

The basic concept of a ggplot2 graphic in R is that you combine different elements into layers. Each layer of a ggplot2 graphic contains information about the following: [more…]

### ggplot2 in R: How to Map Data to Lines, Points, Symbols and More

After you’ve told ggplot() what data to use in R, the next step is to tell it how your data corresponds to visual elements of your plot. This mapping between data and visual elements is the second element [more…]

### How to Define the Data Display Mode in R

A ggplot2 geom in R tells the plot how you want to display your data. For example, you use geom_bar() to make a bar chart. In ggplot2, you can use a variety of predefined geoms to make standard types of [more…]

### How to Create Subsets of Your Data in R

Often the first task in data processing is to create subsets of your data in R for further analysis. You’re already familiar with the three subset operators: [more…]

### How to Subset Data Frames in R

Now that you’ve reviewed the rules for creating subsets, you can try it with some data frames in R. You just have to remember that a data frame is a two-dimensional object and contains rows as well as [more…]

### How to Take Samples from Data in R

Statisticians often have to take samples of data and then calculate statistics. Taking a sample is easy with R because a sample is really nothing more than a subset of data. To do so, you make use of [more…]

### How to Remove Duplicate Data in R

A very useful application of subsetting data is to find and remove duplicate values. R has a useful function, duplicated(), that finds duplicate values and returns a logical vector that tells you whether [more…]

### How to Remove Rows with Missing Data in R

Another useful application of subsetting data frames is to find and remove rows with missing data. The R function to check for this is complete.cases() [more…]

### How to Add Calculated Fields to Data in R

After you’ve created the appropriate subset of your data, the next step in your analysis is likely to be to perform some calculations with R. [more…]

### How to Create Subgroups of Data in R

The cut() function in R creates bins of equal size (by default) in your data and then classifies each element into its appropriate bin.

If this sounds like a mouthful, don’t worry. A few examples should [more…]

### How to Combine and Merge Data Sets in R

You may want to combine data from different sources in your analysis. Generally speaking, you can use R to combine different sets of data in three ways: [more…]

### How to Use the merge() Function with Data Sets in R

In R you use the merge() function to combine data frames. This powerful function tries to identify columns or rows that are common between the two different data frames. [more…]

### How to Work with Lookup Tables in R

Sometimes doing a full merge of the data in R isn’t exactly what you want. In these cases, it may be more appropriate to match values in a lookup table. To do this, you can use the [more…]

### How to Sort and Order Data in R

One very common task in data analysis and reporting is sorting information, which you can do easily in R. You can answer many everyday questions with *league tables* [more…]

### How to Sort Data Frames in R

One way of sorting data in R is to determine the order that elements should be in, if you were to sort. This sounds long winded, but as you’ll see, having this flexibility means you can write statements [more…]

### How to Traverse Data with Apply Functions in R

R has a powerful suite of functions that allows you to apply a function repeatedly over the elements of a list. The interesting and crucial thing about this is that it happens without an explicit loop. [more…]

### How to Use the apply() Function to Summarize Arrays in R

If you have data in the form of an array or matrix and you want to summarize this data, R’s apply()function is really useful. The apply()function traverses an array or matrix by column or row and applies [more…]

### How to Traverse a List or Data Frame with R Apply Functions

When your data is in the form of a list, and you want to perform calculations on each element of that list in R, the appropriate apply function is lapply [more…]

### How to Use Apply to Create Tabular Summaries in R

You use tapply() to create tabular summaries of data in R. With tapply(), you can easily create summaries of subgroups in data. This function takes three arguments: [more…]