R language basics

You can start investigating R by writing simple expressions that include literals and operators. Here are some examples:

1 + 1;
2 + 3 * 4;
3 ^ 3;
sqrt(81);
pi;

This code evaluates three mathematical expressions first using the basic operators. Check the results and note that R, as expected, evaluates the expressions using operator precedence as we know from mathematics. Then it calls the sqrt() function to calculate the square root of 81. Finally, the code checks the value of the base package built-in constant for the number pi (π). R has some built-in constants. Check them by searching help for them with ??"constants".

It is easy to generate sequences. The following code shows some examples:

rep(1,10); 3:7; seq(3,7); seq(5,17,by=3); ...

Get SQL Server 2017 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.