Category Archives: R Data Syntax

Data Concatenation and Coercion in R

Data concatenation and coercion are common operations in R.

Data Concatenation

The concatenate c() function is used to combine elements into a vector.

When elements are combined from different classes, the c() function coerces to a common type, which is the type of the returned value:

Posted in R Data Objects, R Data Syntax | Leave a comment

Data Formatting in R

There are a number of ways to accomplish data formatting in R.

Data Options in R

R supports a range of data formats and controls.  The options() function accesses the default settings R establishes at start-up.  Session options that can be changed from the command line include:

Each of these variables can be changed to modify R performance.  For more details on each element see the HTML help for the options() function.  A practical example is given below.

Posted in R Data Objects, R Data Syntax | Leave a comment

Data Infix Operators in R

Intro to Infix Operators in R

postfixInfix operators in R are unique functions and methods that facilitate basic data expressions or transformations.  

Infix refers to the placement of the arithmetic operator between variables.  For example, an infix operation is given by (a+b), whereas prefix and postfix operators are given by (+ab) and (ab+), respectively.  

The types of infix operators used in R include functions for data extraction, arithmetic, sequences, comparison, logical testing, variable assignments, and custom data functions. 

Posted in R Data Syntax | Leave a comment

Factors in R

Categorical (e.g. qualitative) data are represented as factors in R.  Factors display as character strings (e.g. labels), but are stored as integers (e.g.  levels).

Creating Factors in R

Factors may be created by using the factor() or as.factor() function:

Note that it is not possible to assign labels to the factor levels within the function as.factor().

Another way to create factors in R is to split a data object into category groups and then call the factor() function:

Posted in R Data Objects, R Data Syntax | Leave a comment

R Data Syntax

The following pages introduce the fundamentals of R data syntax for program scripting and quantitative data analysis.  

Back | Next

Posted in R Data Syntax | Leave a comment

Regular Expressions in R

In computing, a regular expression (abbreviated regexp) is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings.  The patterns are often a combination of text abbreviations, metacharacters, and wild cards.  Regular expressions are used for searching for objects, doing extractions, or find/replace operations.  The use of regular expressions offers convenience and can have powerful impact on data or object management.

regexp Functions in R

Functions in R for regular expressions include:

Posted in R Data Syntax | Leave a comment