Starting in R
(→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''.<source lang="rsplus"> | + | the vector to the object named ''v''.<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 |
Revision as of 16:40, 25 January 2015
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