(This article was first published on

**CloudStat**, and kindly contributed to R-bloggers)As stated in CloudStat Intro, we know that CloudStat is based on R Language, an object orientated language, everything in R is an object. Each object has a class. The simplest data objects are one-dimensional arrays called vectors, consisting of any number of elements. For example, the calculation:

Input:

1+1

Output

> 1+1

[1] 2

results in a vector, from the numeric class (as it contains a number), with just one element. Note that the command “1+1” is itself and object of the expression class

The simplest elements produce vectors of the following classes:

- logical: The values T (or TRUE) and F (or FALSE).
- integer: Integer values such as 2 or -5.
- numeric: Floating-point real numbers (double-precision by default).

Numerical values can be written as

whole numbers (for example, 2, -5),

decimal fractions (2.38, -23.125), or in

scientific notation (2.38e57, 23e-98). - complex: Complex numbers of the form a + bi, where a and b are integers or numeric (for example, 5 + 4.67i).
- character: character strings enclosed by matching double quotes (“) or apostrophes ( ’), for example, “CloudStat”, ’data analysis’.

Example: #2 Data Classes Example

> 1+1

[1] 2

>

> T; F #Logical

[1] TRUE

[1] FALSE

>

> 2; -5 #Integer

[1] 2

[1] -5

> 2; -5 #Whole number

[1] 2

[1] -5

> 2.38; -23.125 #Decimal fractions

[1] 2.38

[1] -23.125

> 2.38e57; 23e-98 #Scientific notation

[1] 2.38e+57

[1] 2.3e-97

> 5 + 4.67i #Complex number

[1] 5+4.67i

> "CloudStat"; "data analysis" #Character

[1] "CloudStat"

[1] "data analysis"

>

Two other elements which are particularly useful are:

- factors: These represent labelled observations. For example sex is a factor, generally incorporating two levels: male and female. These are generally used to represent qualitative effects in models.
- ordered factors: A factor where the levels are ordered. For example there may be three responses to a question about quality, high, medium or low, but each level is not necessarily on a linear scale.

Source: An Introduction to R: Examples for Actuaries by Nigel De Silva

To

**leave a comment**for the author, please follow the link and comment on his blog:**CloudStat**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...