Programming in R

Sorted by:  

How to Work with Factors and Numeric Vectors in R Models and Calculations

If you work with factors in R that have numeric values as levels, you have to be extra careful when using these factors in models and other calculations. For example, you convert the number of cylinders [more…]

How to Use the R Help Files

Sometimes you don’t know the exact function to use in R. Other times, you may know exactly what you need. Either way, the R Help Files can be, well…helpful. [more…]

How to Search the Web for Help with R

Sometimes the built-in R Help simply doesn’t give you that moment of inspiration to solve your problem. When this happens, it’s time to tap into the information available on the web. [more…]

How to Find Help Using R Mailing Lists

The R Development Core Team actively supports four different mailing lists. At the R mailing list website, you can find up-to-date information about these lists, as well as find links to subscribe or unsubscribe [more…]

How to Access Alternative Resources for Help with R

Sometimes getting help with R requires you to be a little creative. You may need to access resources that are not on your traditional list of where you usually find help. However, the following options [more…]

How to Make a Minimal Reproducible Example to Get Help with R

When you ask the R community for help, you’ll get the most useful advice if you know how to make a minimal reproducible example. A reproducible example [more…]

How to Provide the Right Information in an R Minimal Reproducible Example

One of the hardest parts of producing an R minimal reproducible example is to keep it minimal. Another is making sure that you provide the necessary information so your problem is indeed reproducible. [more…]

How to Recognize and Fix List Errors in R

Although lists help with keeping data together and come in very handy when you’re processing multiple datasets in R, they can cause some trouble as well. [more…]

How to Use the Formula Interface in R

Another very important idea in R is the formula interface. The formula interface allows you to concisely specify which columns to use when fitting a model, as well as the behavior of the model. [more…]

How to Melt Data to Long Format in R

When using R, consider the words wide and long as visual metaphors for the shape of your data. In other words, wide data tends to have more columns and fewer rows compared to long data. The reshape package [more…]

How to Cast Data to Wide Format in R

If you have a molten dataset (a dataset in long format), you’re ready to reshape it with R. To illustrate that the process of reshaping keeps all your data intact, try to reconstruct the original: [more…]

How to Work With Dates in R

R has a range of functions that allow you to work with dates and times. The easiest way of creating a date is to use the as.Date() function. For example, you write the opening day of the 2012 London Olympic [more…]

How to Present Dates in Different Formats in R

You’ve probably noticed in R that as.Date() is fairly prescriptive in its defaults: It expects the date to be formatted in the order of year, month, and day. Fortunately, R allows you flexibility in specifying [more…]

How to Add Time Information to Dates in R

Often, referring only to dates in R isn’t enough. There are times when you also need to indicate a specific time in hours and minutes in R.

To specify time information in addition to dates, you can choose [more…]

How to Format and Perform Operations on Dates and Times in R

To format a date for pretty printing in R, you use format(), which takes a POSIXct or POSIXltdatetime as input, together with a formatting string.

Using the example where the object [more…]

How to Extract Specific Elements from a Date in R

Another thing you may want to do in R is to extract specific elements of the date, such as the day, month, or year. For example, scientists may want to compare the weather in a specific month [more…]

How to Go Beyond Date and Time Basics in R

If you only know the basics of how to handle dates and times in R, you may want to explore additional functionality available in R and add-on packages by looking at the following: [more…]

How to Add a Second Dimension in R

In addition to vectors, R can represent matrices as an object you work and calculate with. In fact, R really shines when it comes to matrix calculations and operations.Vectors are closely related to a [more…]

How to Play With Attributes in R

Both the names and the dimensions of matrices and arrays are stored in R as attributes of the object. These attributes can be seen as labeled values you can attach to any object. [more…]

How to Extract Values from a Matrix in R

You can use these indices the same way you use vectors in R. You can assign and extract values, use numerical or logical indices, drop values by using a minus sign, and so forth. [more…]

How to Juggle Dimensions and Replace Values in a Matrix in R

By default, R always tries to simplify the objects to the smallest number of dimensions possible when you use the brackets to extract values from an array. So, if you ask for only one column or row, R [more…]

How to Use Standard Operations in a Matrix in R

Probably the strongest feature of R is its capability to deal with complex matrix operations in an easy and optimized way. Because much of statistics boils down to matrix operations, it’s only natural [more…]

How to Do Matrix Arithmetic in R

Apart from the classical arithmetic operators, R contains a large set of operators and functions to perform a wide set of matrix operations. Many of these operations are used in advanced mathematics, so [more…]

How to Create an Array in R

You have two different options for constructing matrices or arrays. Either you use the creator functions matrix() and array(), or you simply change the dimensions using the [more…]

How to Use Dimensions to Extract Values from an Array in R

Extracting values from an array in R with any number of dimensions is completely equivalent to extracting values from a matrix. You separate the dimension indices you want to retrieve with commas. [more…]

Sign Up for RSS Feeds

Computers & Software