**View:**

**Sorted by:**

### 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…]

### How to Create a Bar Chart Using ggplot2 in R

To make a bar chart with ggplot2 in R, you use the geom_bar() function. However, note that the default stat is stat_bin(), which is used to cut your data into bins. Thus, the default behavior of [more…]

### How to Find Minimum or Maximum Values for Functions in R

A very large body of mathematics aims to solve optimization problems of all kinds. In R, the optimize() function provides one fairly simple mechanism for optimizing functions. [more…]

### How to Install and Load CRAN Packages in R

To install a CRAN package in R, use the install.packages() function. This simple command downloads the package from a specified repository (by default, CRAN) and installs it on your machine: [more…]

### How to Unload CRAN Packages in R

By loading a package, R first loads the package and then attaches the package and to your search path, which you can see as an internal database that tells R where to find functions and objects. Whenever [more…]

### How to Make Scatterplot and Line Charts in R with ggplot2

If you have downloaded and imported ggplot2 for use in your R installation, you can use it to plot your data. To create a scatterplot, you use the geom_point [more…]

### How to Plot Summarized Data in a ggplot2 in R

One very convenient feature of ggplot2is its range of functions to summarize your R data in the plot. This means that you often don’t have to pre-summarize your data. For example, the height of bars in [more…]

### How to Work with Scales in a ggplot2 in R

In ggplot2 in R, scales control the way your data gets mapped to your geom. In this way, your data is mapped to something you can see (for example, lines, points, colors, position, or shapes). [more…]

### How to Add Row and Column Totals in R

One task that you may frequently do in a spreadsheet that you can also do in R is calculating row or column totals. The easiest way to do this is to use the functions [more…]

### How to Format Numbers in R

When you produce reports in R, you will want your numbers to appear all nicely formatted to enhance the impact of your data on the viewer. You can use [more…]

### How to Use CRAN to Find R Code and Packages

The Comprehensive R Archive Network CRANis a network of web servers around the world where you can find the R source code, R manuals and documentation, and contributed packages. [more…]

### How to Install R

You can find the installation files and all necessary information regarding installation on one of the mirror sites of the Comprehensive R Archive Network [more…]

### Unique Features of R

R is more than just a domain-specific programming language aimed at data analysis. It has some unique features that make it very powerful, the most important one arguably being the notion of [more…]

### How to Start Your First R Session

You probably are itching to get started on some real R code. Here, you get to do exactly that. Get ready to get your hands dirty and dive into the programming world! [more…]

### How to Find and Add Packages to Your R Installation

If you’re just getting started with R, you’ve probably used only functions that are available in the basic installation of R. But the real power of R lies in the fact that anyone can write their own functions [more…]

### How to Handle Infinity in R

In some cases, you don’t have real values to calculate with. In most real-life data sets in R, in fact, at least a few values are missing. Also, some calculations have infinity as a result [more…]

### Discovering the Properties of Vectors in R

Vectors have a structure and a type, and R is a bit sensitive about both. Feeding R the wrong type of vector is like trying to make your cat eat dog food: Something will happen, and chances are that it [more…]

### How to Combine Vectors in R

To dive a bit deeper into how you can use vectors in R, let’s consider this All-Star Grannies example. You have two vectors that contain the number of baskets that Granny and her friend Geraldine scored [more…]

### How to Recycle Arguments in R

Each time, you combine a vector with multiple values and one with a single value in a function. R applies the function, using that single value for every value in the vector. But recycling goes far beyond [more…]

### How to Search Text by Pattern in R

Like any programming language, R makes it easy to compile lists of sorted and ordered data. To find substrings, you can use the grep() function, which takes two essential arguments: [more…]

### How to Name Matrix Rows and Columns in R

The rbind() function in R conveniently adds the names of the vectors to the rows of the matrix. You name the values in a vector, and you can do something very similar with rows and columns in a matrix. [more…]

### Tips for More Date and Time Functionality in R

Once you have a really good grip on using date and time, you may want to explore additional functionality available in R and add-on packages by looking at the following: [more…]

### How to Create a Data Frame from a Matrix in R

You can create a data frame from a matrix in R. Take a look at the number of baskets scored by Granny and her friend Geraldine. If you create a matrix [more…]

### Naming Observations in R

One important difference between a matrix and a data frame in R is that data frames always have named observations. Whereas the rownames() function returns [more…]

### How to Extract Variables, Observations, and Values from a Data Frame in R

In many cases, you can extract values from a data frame in R by pretending that it’s a matrix. But although data frames may look like matrices, they definitely are not. Unlike matrices and arrays, data [more…]