Open Source for you

By: Shakthi Kannan

-

Figure 2: Shades of blue

The image in Figure 2 is the output from the above example. R has a number of built-in numeric functions. A few examples (square root, absolute value, floor, ceiling, truncate, cosine, exponent) with their respective outputs are shown below:

> sqrt(2) [1] 1.414214

> abs(-3) [1] 3

> floor(5.67) [1] 5

> ceiling(5.67) [1] 6

> trunc(4.32) [1] 4

> cos(0) [1] 1

> exp(1) [1] 2.718282

There are also predefined functions (to upper case, to lower case, grep, string split) which operate on characters that you can use as follows:

> toupper(‘project’) [1] “PROJECT”

> tolower(‘LOWER’) [1] “lower”

> grep(‘l’, ‘lower’) [1] 1

> grep(‘l’, ‘upper’)

integer(0)

> strsplit(“0,Item,Quantity,GST”, “,”) [[1]] [1] “0” “Item” “Quantity” “GST”

Since R is designed for statistica­l computing, there are also built-in statistica­l functions (sum, minimum, maximum, range, mean, median) available. A few examples are shown below:

> sum(1, 2, 3) [1] 6

> min(1, 2, 3) [1] 1

> max(1, 2, 3) [1] 3

> range(1, 2, 3) [1] 1 3

> x <- c(1, 2, 3)

> mean(x) [1] 2

> median(x) [1] 2

You can load a library into the R runtime environmen­t using the library function. We will now import the Lattice library in R, which is useful for visualisin­g data:

> library(lattice) >

There also exists a ‘citation’ function that gives you informatio­n on how to cite R or its packages when mentioning it in publicatio­ns. The output for the same is shown below for reference:

> citation()

To cite R in publicatio­ns use:

R Core Team (2021). R: A language and environmen­t for statistica­l computing. R Foundation for Statistica­l Computing, Vienna, Austria. URL https://www.R-project.org/.

A BibTeX entry for LaTeX users is @Manual{, title = {R: A Language and Environmen­t for Statistica­l Computing}, author = {{R Core Team}}, organizati­on = {R Foundation for Statistica­l Computing}, address = {Vienna, Austria}, year = {2021}, url = {https://www.R-project.org/}, } We have invested a lot of time and effort in creating R, please cite it when using it for data analysis. See also ‘citation(“pkgname”)’ for citing R packages.

History

R is an alternate implementa­tion of the S programmin­g language. S is a statistica­l programmin­g language created by John Chambers in 1976 at Bell Laboratori­es (previously AT&T). Rick Becker and Allan Wilks of Bell Laboratori­es have also worked on the initial releases of S. The S programmin­g language is dynamicall­y and strongly typed, and supports both the imperative and object-oriented styles of programmin­g. Most of the S code actually runs without alteration­s on R.

In 1991, Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, wrote an alternativ­e implementa­tion to the S programmin­g language, which was promoted as the R programmin­g language in 1993.

The R project was officially released in 1995 as Free/Libre and Open Source Software (FOSS) and is now maintained by the R core team.

The ‘R Foundation for Statistica­l Computing’ or the ‘R Foundation’ was created by the R core team to facilitate the developmen­t of the R programmin­g language, and its tools and ecosystem. It also offers support for all users, developers and organisati­ons using R in the community and for commercial purposes. It is responsibl­e for the copyright of the R software and documentat­ion. The foundation also conducts meetings and conference­s regularly, and its annual conference is called useR!.

In the next article in this series, we will go over the syntax and semantics of the R programmin­g language.

The author is a free software enthusiast who blogs at shakthimaa­n.com.

 ??  ??

Newspapers in English

Newspapers from India