Recently began to learn the R language, the study notes and small friends to share, welcome to Exchange
R Origin:
R is an implementation of the S language. s language is an interpretive language developed by T-Bell Labs for data exploration, statistical analysis, and graphing. The original implementation version of the S language was mainly s-plus. S-plus is a commercial software that is based on the S language and is further perfected by the Department of Statistical Science of Mathsoft Corporation. Later Robert Gentleman and Ross Ihaka and other volunteers at Auckland University developed an R system. There are many similarities between the use of R and S-plus, two software has a certain compatibility.
R is the language and operating environment for statistical analysis, plotting. R is a free, free, source-code software that belongs to the GNU system and is an excellent tool for statistical computing and statistical mapping.
R is a complete set of data processing, calculation and mapping software system. Its functions include: data storage and processing system, array arithmetic tool (which is particularly powerful in vector and matrix operation); a complete and coherent statistical analysis tool; excellent statistical mapping function; Simple and powerful programming language: can manipulate the input and input of data, can realize branch, loop, user can customize function. R is a free software, it has UNIX, LINUX, MacOS and Windows version, are free to download and use, where you can download to the R installation program, a variety of plug-ins and documents. Only 8 basic modules are included in the R installer, and other external modules can be obtained via Cran.
R Basic Operation:
Click on the R language to see the following interface, which is our internal algorithm and the R language of the main way to interact.
">" Similar to the input prompt under CMD, we can enter data from here, to do data processing and so on. First we input two arrays: x1= C (1 2 3 4 5) and X2=c (' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ') where "C ()" is a function of the input array of r language, each line of R language can only perform one operation, enter the X1 after entering the X2; The data is stored in memory and can be manipulated in pairs (1,2,3,4,5) by simply invoking the X1 identifier.
1, the basic operation of the array:
1), view array---directly call the array name return;
2), get array element according to subscript---call array name + square brackets + element subscript;
3), view the length of the array (length ());
4), view array element type (mode (); PS: The language supports only array element single types, and all elements are either characters or values.
5), the operation of the array also includes the inclusion of multiple arrays, you can combine the two array of arrays of a matrix (R language called a data frame: frame), you can combine the array rbind () and the column direction combination cbind ();
Ps: The result of merging a character type array with a numeric type array is that the new matrix element is a string type;
The specific use and output are as follows:
2, the statistical indicators of the array processing:
Common statistical indicators include: average (mean ()), SUM (sum ()), Multiplication (prod ()), Maximum (min (), Max ()), Variance (Var ()), Standard deviation (SD ())
First of all, we first generate 1 to 100 numbers by using R's fast generating Array function C (startnum:endnum) and store in the array y, and then output the corresponding statistic indicators, see:
3, about the data subscript related processing
R language provides a useful subscript processing function, we can easily remove the ideal data, such as:
1), take the continuous subscript element;
2), according to the value of the other array elements to take---with the value of the other elements of the array to remove the corresponding subscript elements of this array;
3), according to the size of the element value, such as can be removed in the array is greater than a certain number of all elements, less than a certain number of all elements, and so on;
4), the practical which function, which in the array subscript to represent the array object, you can remove the array element A[which ()] by which, corresponding can also take out the subscript which () conforming to the element;
5), self-sorting function (sort ()) and array inversion function (rev ());
The specific use and output are as follows:
3. Generate matrix and matrix operation related functions:
R provides a function of the array-to-matrix (Matrix ()), and the matrix is the beginning of a lot of subsequent work:
1), matrix to add and subtract (+-), multiply (%*%):
Ps: When arrays are generated, the default is to follow the direction of the column, and you can add the parameter byrow=t to generate the matrix in line direction.
2), Take diagonal (Diag ()), transpose (T ())
3), Inverse (solve), solving the linear equation Group (solve):
Eigenvalue eigenvector (Eigen ())
Basic data structure for r language-data frame
The data frame is also a matrix, but unlike the general matrix, the columns in the NC box can be different data types, each column is a property value, each row is a record, or an observation of all the properties of an object.
The R language reads external data---text data:
Logic loop Control:
The R language supports a for loop and a while loop, and the two loops are structurally similar to a common programming language, but with a few differences.
Array subscript in ps:r starting from 1; R does not support "+ +"
Today is posted to this, hope to help small partners, next time to change the R language of the drawing.
R and Data Analysis Learning Summary: basic operation of R language