My Coding >
Software >
R >
R vectors
R vectorsOne of the basic R data is vector. All elements in vector should be the same type. Initialization of the vector in RWe can create integer range using the colon : syntax. Range can be increasing or decreasing
We can specify exact values using the c function. We can also use all values from existing vector
It is possible to use range in C function
We can use function seq to specify some sequences. For example with small step, or fixes amount of steps
Initialization with key-value pairWe can initialize vector with key-value pairs.
To access to individual value we need to use function unname()
To see all names, we can use function names()
Access to datausing square brackets [ ] we can access to any data in our vector
If we call element [0] we will receive type of data. We can also check data type by call typeof function
Three equivalent calls for range >###CODE+### w[1:3] [1] 5 10 2 > w[c(1, 2, 3)] [1] 5 10 2 > w[c(1:3)] [1] 5 10 2 ###CODE-### Exclude one element for output – ve need to call it negatively. But element will not be deleted from the list
Boolean filteringWe can use boolean filtering in square brackets
or something more simple
Vector manipulating in RLet’s create vectors for manipulating first
Modify individual value
Modify all values which are obey some boolean filtering
Adding constant to vector (actually ve can do any mathematical operations)
Element wise operations + - / *
If you divide by 0 you will have inf value
Basic analysis of the vector contentThere are few very important functions to work with vector:
Summary() produce few most important object properties. And it is possible to access them as to vector with key-value pairs
Vector sortingVector can be sorted in R in Increasing by default or decreasing order
By default, sorting function sort() remove all NA values. To keep them ,you need to raise flag na.last=TRUE
|
Last 10 artitles
9 popular artitles
|
|
© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit. |