Features Of R :
1) R is a well-developed, simple and effective programming
language which includes decision making , flow control, recursive, functions
input and output methods
2) R has an
effective data handling and storage facility which is important for statistical
analysis.
3) R
Provides a variety of operators for calculations on arrays, lists, vectors and
matrices.
4) R
provides a large, coherent and integrated collection of packages and tools for
data analysis including mathematical symbols. Dynamic and interactive graphics
are available through additional packages
5) R and its
libraries implement a wide variety of statistical and graphical techniques,
including linear and non linear modelling, classical statistical tests,
time - series analysis, classification,clustering and others
6) R is
easily extensible through function and extensions. R community is noted for its
active contribution in terms of packages. For computationally intensive tasks,
C, C++ and Fortran code van be linked and called at run time. Advanced users
can write C/C++, Java , .NET or Python code to manipulate R objects directly
7) Since R
was inherited from a language called S , R has stronger objective-oriented
programming facilities than most statistical computation languages
Identifiers:
The
unique name given to variable like function or object is known as an identifier
. Following are the rules for naming an identifier.
a) Identifier can be a combination of
letters, digits, period, and underscore(_).
b) It must start with a letter or a period. If
it starts with a period, it cannot be followed by a digit.
c) Reserved word in R cannot be used as
identifiers
Examples
of some valid identifiers are: total, sum, .date, .date.of.birth,sum_of_two
Example
of some invalid identifiers are : tot@l,2um, _prod, TRUE, .0wl
Earlier
version of R used underscore (_) as an assignment
operator. So, the period (.) was used extensively in variable names having multiple
words.
Constants
:
Constants
or literals, as the name suggest, are entities whose values cannot be altered.
Basic type of constants are numeric and character constants. They are built-in
constants also.
All
numbers fall under this category. They can be of type integer, double, or
complex, We can check the type of constants by typeof() function.
Variables:
A variable
provides us with named storage that our programs manipulate. A variable in R
can store an atomic vector, group of atomic vectors or a combination of many R
objects. A valid variable name consists of letters, numbers and the dot or
underline characters. The rule for naming a variable is same as that of any
identifiers which is already discussed above.
The
variable can be assigned values leftward, rightward and equal to operator. The
values of the variables can be printed using print () or cat ()function. The
cat() function combines multiple items
into a continuous print output.
Operators
:
R has
several operator to perform tasks arithmetic, logical and bitwise operations. R
provides following types of operators . They are
a) Arithmetic operator
b) Relational Operator
c) Logical Operator
d) Assignment Operator
e) Miscellaneous Operator
Arithmetic
operator:
These
operators are used to carry out mathematical operations, like addition,
subtraction, multiplication, division. The arithmetic operators are applied for
vectors. Even if we give a single value, it is considered as a vector with
length one.
Relational
operator :
Relational
operator are used to compare between values. Each element of the first vector
is compared with the corresponding element of the second vector. The result of
comparison is a Boolean value.
Logical operator :
Logical operator are applicable only to vectors of type logical,
numeric or complex. All numbers greater than 1 are considered as logical value
TRUE. Each element of the first vector is compared with the corresponding
element of the second vector. The result of comparison is Boolean value.
Operator
|
Description |
! |
Logical
Not, Takes each element of the vector and gives the opposite logical value |
& |
Element
wise logical And. It combines each element of the first vector with
corresponding element of the second vector and gives an output TRUE if both
the values are TRUE. |
&& |
Logical
AND. It takes first element of both the vectors and gives TRUE only if both elements are TRUE |
| |
Element-wise
logical OR. It combines each element of the first vector with the
corresponding element of the second vector and gives an output TRUE if one of
the elements is TRUE |
|| |
Logical
OR. It takes first element of both the vectors and gives an output TRUE if
one of the element is TRUE |
Assignment
Operator :
These
operators are used to assign values to variables or vectors. The operators <-
and = can be used almost interchangeably to assign values to a variables in the
same environment.
The
<<- operator is used for assigning values to variables in the parent
environments
Operators
|
Description |
<-,<<-,= |
Leftward
assignment |
->,->> |
Rightward
assignment |
Miscellaneous operator :
These operator are used for specific purpose. They are not
used for mathematical or logical computation.
Operators |
Description |
: |
Colon. It creates a range of numbers in sequence for a vector. |
%in% |
This operator is used to check whether an element belongs to a vector
or not. The result will be a Boolean value either TRUE or FLASE. |
%*% |
This operator is used to multiply a matrix with its transpose |
Strings:
Strings are created in R by writing any value within a pair
of single quote or double quotes. However, internally R stores every strings
within double quotes, even if we create
them with single quote. The quotes at the beginning and end of a string should
be both double quotes or both single quotes. They cannot be mixed. Another
feature of string is that double quotes can be inserted into a string staring
and ending with single quote. Similarly single quote can be inserted into a
string a staring and ending with double quotes.
Reading String :
We can read string from keyboard using the readLines ()
function . It lets the user to enter one-line string at the terminal . The
syntax as follows :
a <- readLines("stdin", n=1);
0 Comments:
Post a Comment
If you have any doubts . Please let me know.