Basic Syntax, Data Types and Variables
In this chapter we will learn to write the simplest program of writing “Hello World” in R programming language. In this programme we will use function print() to display this string.
Usually the string will be displayed with double quotes. However in order to avoid that put, quote=FALSE.
Variables and Data Types in R Programming
Variables and Constants are two important concepts of R programming which form the fundamental of this language. This chapter will summarize the theory of these two terms along with small examples.
variables are similar to an open box, where you can put any value of your wish. You can change the values as well. One thing to be noted here that the variable name should be different from the reserved words. Some of the key points to be remembered while defining variables are-
- Variable names can be a combination of letters, numbers, underscore, etc.
- The names should start with a letter or a period, however in latter case, the period cannot be followed by a digit.
- reserved words cannot be used as identifiers.
Constants can be defined as the entities whose values cannot be changed. Basically there are two types of constants:
- Numeric constants – It includes all the numbers. Three basic types of these variables are integer, double, complex. The numeric constants which are followed with L are considered as integers and i are regarded as complex. On the other hand, the constants with 0x or 0X at the end are considered as hexadecimal.
- Character constants – These constants are defined with single (‘ ‘) or double quotes (” “) known as delimiters.
There are 5 data types in R Programming which are described below:
- Numeric – Decimal values are referred to as numeric data type. For example, 1.23.
- Integer – It includes the integer numbers. For example, 1, 2, 3.
- Complex – It consists of complex numbers, such as, i+2.
- Logical – Where logical operators are used. such as a<b.
- Character – Represented using double quotes. For example, “123”.