Programming in R

Sorted by:  

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

How to Work with Non-CSV Data Files in R

Despite the fact that CSV (comma-separated values) files are very widely used to import and export data in R, they aren’t always the most appropriate format. Some data formats allow the specification of [more…]

How to Get Your Data Out of R

For the same reason that it’s convenient to import data into R using CSV (comma-separated values) files, it’s also convenient to export results from R to other applications in CSV format. To create a CSV [more…]

How to Add Color and a Key to Lattice Charts in R

Many lattice graphics types in R — but bar charts in particular — tend to display multiple groups of data at the same time. Usually, you can distinguish different groups by their color or sometimes their [more…]

How to Determine a Data Structure in R

The first decision you have to make before analyzing your data is how to represent that data inside R. If your data has only one dimension, then you already know that vectors represent this type of data [more…]

How to Debug Your Code in R

Once you have written your code in R, it is important to know how to debug it. To err is human, and programmers fall into that “human” category as well. Nobody manages to write code without errors, so [more…]

How to Read Errors and Warnings in R

If something goes wrong with your code, R tells you. We have to admit it: These error messages can range from mildly confusing to completely incomprehensible if you’re not used to them. But it doesn’t [more…]

How to Know When to Care About Warnings in R

Errors and warnings have different functions in R You can’t get around errors, because they just stop your code. Warnings on the other hand are a whole different beast. Even if R throws a warning, it continues [more…]

How to Hunt for Bugs in R

Hunting for Bugs in R can sometimes be a tricky situation. Although the error message always tells you which line of code generates the error, it may not be the line of code where things started going [more…]

How to Tell R which Function to Debug

You can step through a function after you tell R you want to debug it using the debug() function, like this: [more…]

How to Step Through Debugging an R Function

You can step through a function after you tell R you want to debug it using the debug() function. From then on, R will switch to the browser mode every time that function is called from anywhere in R, [more…]

How to Generate Your Own Error Messages in R

Generating your own messages may sound strange, but you can actually prevent bugs in R by generating your own errors. Remember the logic error in the logitpercent [more…]

How to Fix Data Reading Errors in R

Probably the most common mistakes in R are made while reading in data from text files using read.table()or read.csv(). Many mistakes result in R throwing errors, but sometimes you only notice something [more…]

How to Identify and Correct Dropped Dimensions in R

Every function in R expects your data to be in a specific format. That doesn't mean simply whether it's an integer, character, or factor, but also whether you supply a vector, a matrix, a data frame, or [more…]

Sign Up for RSS Feeds

Computers & Software