R is a statistical analyzation language, and that means it is very good at data manipulation and data analyzation. One key way to analyze data is through plotting, and R excels in this field.
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
=========================== to be checked ===================
R operates on named data structures. The simplest such structure is the numeric vector, which is a single entity consisting of an ordered collection of numbers. To set up a vector named v, say, consisting of five numbers, namely 1.5, 3.1415926, 3.17, 4.55 and 31.8, use the R command
Notice that the assignment operator (‘<-’), which consists of the two characters ‘<’ (“less than”) and ‘-’ (“minus”) occurring strictly side-by-side and it ‘points’ to the object receiving the value of the expression. In most contexts the ‘=’ operator can be used as an alternative.
Assignment can also be made using the function assign(). An equivalent way of making the same assignment as above is with:
The further assignment
Vectors can be used in arithmetic expressions, in which case the operations are performed element by element. Vectors occurring in the same expression need not all be of the same length. If they are not, the value of the expression is a vector with the same length as the longest vector which occurs in the expression. Shorter vectors in the expression are recycled as often as need be (perhaps fractionally) until they match the length of the longest vector. In particular a constant is simply repeated. So with the above assignments the command
c(min(x), max(x))
.
sort(x)
returns a vector of the same size as
x with the elements arranged in increasing order;
however there are other more flexible sorting facilities available
(see order() or sort.list()).
Generate vector of n = 5 (for example) uniform random vals between 0 and 1
norm(matrix(v),’1’)
norm(matrix(v),’i’)
sum(abs(v)^p)^(1/p)
Compute mean of all elements in vector v
mean(v)
sd(v)
var(v)
sum(x*y)
Example:
The paraboloid example shows that any function with three variables can be visually represented using the plot
and plotly
functions.
Next, we utilize anothe rpackage plotly for creating interactive web-based graphs via the open source JavaScript:
Example: We plot a torus with the follwoing commands: