Starting in R

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
(Vector.)
(Vector.)
Line 9: Line 9:
 
It is an object with only one dimension. To show how to access the data, lets create an object named ''v''
 
It is an object with only one dimension. To show how to access the data, lets create an object named ''v''
 
which contains the 9 integer numbers, from 1 to 9. This vector can be created by using the ''c()'' function, where the arguments are the numbers to be concatenated in a vector. The "arrow" ''<-'' assigns  
 
which contains the 9 integer numbers, from 1 to 9. This vector can be created by using the ''c()'' function, where the arguments are the numbers to be concatenated in a vector. The "arrow" ''<-'' assigns  
the vector to the object named ''v''.
+
the vector to the object named ''v''.<source lang="rsplus">  
<source lang="rsplus">  
+
 
v <- c(1,2,3,4,5,6,7,8,9)
 
v <- c(1,2,3,4,5,6,7,8,9)
 
v
 
v
 
## [1] 1 2 3 4 5 6 7 8 9
 
## [1] 1 2 3 4 5 6 7 8 9
 
</source>
 
</source>
 
 
The third element of the vector can be accessed by indicating its  
 
The third element of the vector can be accessed by indicating its  
position inside square brackets after the name of the object as follows:
+
position inside square brackets after the name of the object as follows:<source lang="rsplus">  
<source lang="rsplus">  
+
 
v3
 
v3
 
## [1] 3
 
## [1] 3
 
</source>
 
</source>
 
 
an interval of consecutive elements, for instance the elements from the  
 
an interval of consecutive elements, for instance the elements from the  
second to the fourth can be accessed by:
+
second to the fourth can be accessed by:<source lang="rsplus">  
<source lang="rsplus">  
+
 
v3:4
 
v3:4
 
## [1] 3 4
 
## [1] 3 4
 
</source>
 
</source>
 
non-consecutive elements, like the second and the seventh element can be  
 
non-consecutive elements, like the second and the seventh element can be  
accessed by:
+
accessed by:<source lang="rsplus">  
<source lang="rsplus">  
+
 
v[c(2,7)]
 
v[c(2,7)]
 
## [1] 2 7
 
## [1] 2 7

Revision as of 16:39, 25 January 2015

Construction.png sorry: 

This section is still under construction! This article was last modified on 01/25/2015. If you have comments please use the Discussion page or contribute to the article!

R is an object-oriented programming language. Each object has data fields which are attributes that describes the object. The script defines how these objects are created, imported or exported, and also the interaction among them. The result of the calculus is always a new object, which can be stored (assigned), or only displayed in the console. There are many different types of objects in R. Moreover, the information inside the objects has different data modes. Below, the most frequent types of objects and data modes are introduced.

Types of objects in R

Even though there are many different types of objects in R, here we will only present the most frequent. Each object has different ways of accessing to the data stored inside. Hereinafter the different types of objects are listed and the way to access to the data is explained.

Vector.

It is an object with only one dimension. To show how to access the data, lets create an object named v which contains the 9 integer numbers, from 1 to 9. This vector can be created by using the c() function, where the arguments are the numbers to be concatenated in a vector. The "arrow" <- assigns

the vector to the object named v.
 
v <- c(1,2,3,4,5,6,7,8,9)
v
## [1] 1 2 3 4 5 6 7 8 9

The third element of the vector can be accessed by indicating its

position inside square brackets after the name of the object as follows:
 
v3
## [1] 3

an interval of consecutive elements, for instance the elements from the

second to the fourth can be accessed by:
 
v3:4
## [1] 3 4

non-consecutive elements, like the second and the seventh element can be

accessed by:
 
v[c(2,7)]
## [1] 2 7

all elements with a value bigger or equal than 6 can be accessed by using the which() function inside the square brackets as follows:

 
v[which(v>=6)]
## [1] 6 7 8 9
Personal tools
Namespaces

Variants
Actions
Navigation
Development
Toolbox
Print/export