R Language Learning Notes

Source: Internet
Author: User
Tags natural logarithm

R free to use; statistical tools;
# Notes
Block Comment: anything= ""
Editor: Rsutdio,tinn-r,eclipse+statet; Chinese will be garbled
?, Help: BoxPlot, Help (BoxPlot), Help ("[[")
Source (' ABC. R ')
Library (GGPLOT2)
Install.packages ()
Q ()
SETWD ("e:\\xxx\\yyy\\")
RM (List=ls (all=true))
Log natural logarithm; log10;
Scalar
Assignment Value: <-,=
Variable name can be used.
c () vector; win[1], Win[1:5], win[-2], subscript starting from 1;
C () can be connected to multiple scalars, or multiple vectors can be connected;
NA
Variable named capital Letter start
Na.rm=true
Rep (); Rep (1:4, each=8)
Seq (); Seq (from=1,to=4,by=1)
Cbind ()
Rbind ()
Matrix (); Matrix (nrow=8,ncol=4); z[,1], z[1:8,1], z[2,], z[,-3], Z[,c (1,3,4)]
Dim (Z)
Nrow (); Ncol ();
Vector (length=8)
Colnames ()
Rownames ()
As.matrix;as.data.frame,is.matrix, Is.data.frame,
T ()
Xx<-data.frame (AA=AA,BB=BB); XX$AA; xx[,1];
STR ()
Names ()
List (X1=X1,X2=X2)
Is.na ()
!is.na ()
Read.table () generates a data frame
Scan () is faster than the numeric type
Write.table ()
Factor
Attach (); Detach ();
Unique ()
Filtering subsets: sel<-squid$sex==1; squidm<-squid[sel,]; Squid[squid$sex==1,];
|, &,! =, = =
Order ()
Merge ()
As.factor (); As.numeric (); As.character ();
Factor (Squid$sex, Levels=c), Labels=c ("M", "F"))
Tapply (); Tapply (X=veg$r,index=veg$transect, Fun=mean) averages the first variable according to the different levels of the second variable;
Mean,min,max,sd,length,
Lapply () multiple variables; output list;lapply (X,fun=mean)
Sapply () multiple variables; output vector; Sapply (X,fun=mean)
Summary () output minimum, first four, median, average, third four, maximum;;
Table () computes a list of tables; A variable or two variables;
Plot (); Plot (X=XXX,Y=YYY); Plot (Y~x,data=veg);
Plot (x=,y=,xlab=,ylab=,main=,xlim=,ylim=), pch=1..25;
Warnings ()
Col color; cel size; CeX size;
Lines () Dash; Loess () loess smoothing; fitted () fitting value;
LWD line width, lty line type;
JPEG (file= "xxxx.jpg"); Dev.off ();
Paste (); Paste0 ();

For (i-1:27) {}
for (var in seq) expr
while (cond) expr
Repeat expr
Break
Next

if (cond) expr
if (cond) cons.expr else alt.expr



IfElse (choice== "Zeros", EXPR1,EXPR2);

Custom functions
Function_name<-function (params) {
Do something
Expr--return values;
}

Colsums (); Rowsums ();
function parameter Default value
Function_name<-function (params, xxx= "YYY") {
Do something
Expr--return values;
}


A beginner's guide to the R language
LS (); LS (pat = "M"); LS (pat = "^m")
Help ("BS", try.all.packages = TRUE); Help ("BS", package = "splines")
Help.search ("tree", rebuild = TRUE))
The type and length of the object can be obtained by means of the function mode and
\", \‘
function scan is more flexible than read.table, one of their differences is that the former can specify the type of the variable
MyData <-Scan ("Data.dat", what = List ("", 0, 0)) reads three variables in the file Data.dat, the first is the character type variable, and the second is the value
Type variable.
function READ.FWF can be used to read data in some fixed-width format in a file
If you want to write an object to a file in a simpler way, you can use the command write (x,file = "Data.txt"), where x is the name of the object (it can be a vector, a matrix, or a number
Group
To record an object of any data type, we can use the command save (x, Y, z,file= "xyz. RData ").
Data (called Workspaces in terms of R) can be used in load ("XYZ. RData ") is then loaded into memory.
Keyboard input Some data is also possible, only need to directly use the default option of the scan function:
The function sequence creates a series of sequential integers, each ending with the value of the given parameter
Function GL (generate different levels/levels of data)
Expand.grid () Create a data frame

Mathematical operations comparison operational logic operations
+ Addition < less! X Logical Non-
-Subtraction > greater than X & y logic and
* Multiplication <= is less than or equal to x && y ibid.
/Division >= greater than or equal to X J y logic or
^ Exponent = = equals x JJ y ibid.
Percent Modulus! = is not equal to XOR (x, y) xor
%/% divisible

Identical and All.equal
If x is a matrix, the command Data.entry (x) opens a graphical editor and can modify the value by clicking on the appropriate cell or adding a new row or column

R Language Learning Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.