One, the working layer that the R language handles:
Explain:
The bottom layer is the data source, up to the Data Warehouse layer, up to the data exploration layer, including statistical analysis, statistical queries, and reports
The top three layers, respectively, are data mining, data presentation and data decision-making.
It is known that the R language can be used for data mining, data presentation, and then leadership based on the data presented to make decisions, r language in the aspect of data presentation, has a very powerful function.
Second, the data structure of the R language:
These include the following: vectors, matrices, arrays, data frames, lists, and factors
1, Vector:
There are three ways to create vectors, respectively:
First, use this method of C ():
Since the blog has the option of the R language code for the wood, so, choose below:
To explain, it is to create x1 vectors, x2 vectors, and then use the length () and the mode () function respectively, to get the lengths of the vectors and the type of the vectors, the type of the vector shown above is numeric, which is the number type.
Then, using Rbind (X1,X2) and Cbind (X1,X2) Two methods, respectively, the two vectors are combined with row and column.
So can vectors be of other types? The answer is obviously yes, as shown below, as long as the vector contains a string, then the vector is a character type.
The second method of creating vectors, and the interception of vectors:
The above code shows that, without writing C, you can use ":" To complete the creation of a vector, while at the same time, it is common to determine the specific form of the vector created by adding and minus multiplication.
The selection of the elements in the vector is the same as that of the array in the other language, and the difference is that he can pick a minus sign, and then the result is to remove the other elements after the element
This method is not only applicable to a single element, still applies to multiple elements, multiple elements of the time using ":" To complete.
The third way to create vectors:
This way of creation, long and the first method is somewhat the same, the effect of the second method is a bit similar to the effect, where by its representation of the difference, length is the number, according to the number to determine how much variance
The summary comparison of the three methods of creating vectors seems to be a conclusion:
First, suitable for creating vectors with a limited number of elements
The second, which is suitable for creating a large number of elements, but the relationships between these elements are not so strongly vector
Third, suitable for creating vectors with a linear nature
In the following, there is also a way to create vectors .....
Finally there is a vector, which is a constant vector built into the R language, used to denote 26 letters such as A,B,C,D...Z.
2, using a specific function, to manipulate the vector
This includes the which function, where Which.max () and which.min () are used for the subscript of the maximum and minimum values in the orientation amount respectively, note that the subscript is not the corresponding value
can also be used to go to the subscript of a specific range and a specific value
Then the Rev () function and the sort () function, respectively, for reversal and sorting
2, Matrix
Unlike the method of creating vectors, there is only one way to create a matrix, and it is the result of sorting the vectors by column and by row on the basis of the vectors.
From the above, the preceding three methods for creating vectors are wrong, and the C () method can obviously be used to create a large number of vector elements.
When using the matrix method to combine vectors, the default is to install the column to order the combination of books, such as the first, the matrix, according to the column, the first column is three-way, the second column is 4,5,6 so is the obvious column,
If you use Byrow=t instead, arrange by row instead
3, array
4, Data frame
There is only one way to build a data frame, and he has a combination of vectors, which can be seen, the vector is the most fundamental of the R language data structure, if there is no vector, everything is not.
At the same time, unlike the Matrix, each of his columns can be different types than the other columns
5,factor
, Iris is a data frame built into the R language, and you can select one of the columns if you use Facotor
As indicated, is to go to the value of the column, the literal meaning is to obtain the influence factor, if it is each one when the eigenvalues of a thing
6, List
The so-called list can be thought of as an ordered set of elements, and the order in which he is stored is apparently equal to the sequence of the books taken out.
Third, the R language calculates the related functions:
General Operations:
As shown, mean () is averaged, sum () is summation, Max () is the maximum, Min () is the minimum value
matrix operations,
Including subtraction, finding eigenvalues and eigenvectors, etc.
There is nothing special about the addition and subtraction, and it is important to note that T () is a transpose, he has a great effect, and can be transformed into a matrix, as shown in:
The transformation to the row matrix is completed, and the transformation of the row matrix to the column matrix is completed.
The multiplication of matrices is%*%, pure * Just the multiplication of the elements of the matrix.
The Diag () function allows you to get the elements of a list object line based on a matrix, and, of course, to create a matrix based on the elements on the diagonal.
can also be used to construct a unit array
As calculated below, the rnorm is the random number to go, and the solve () function is used to derive the inverse matrix of matrix A, that is, the division of the Matrix
As shown, the solve function can still be used to solve the equation set:
As shown, the Eigen function is used to obtain a matrix of eigenvectors and eigenvalues, and can be used to remove
Four, R's statement:
For statement:
Unlike other syntaxes, for loops, there is no need to initialize the value, a or B has an initialized value
While Loop statement:
Unlike the above, a needs to have an initial value, but also to control the addition and subtraction of I
Five, some of the other special functions:
Note that in the text, if you want to load this file to print, you need to use the print () function in the code of the text ...
R Language Analysis (i)-----basic syntax