Introduction to the R language

Source: Internet
Author: User

Learning materials: "R language Combat"

R is a language and environment for statistical computing and Mapping, a set of open source data analysis solutions.
1, the Novice on the road

Author Forum: http://www.statmethods.net/

Data download URL: https://www.manning.com/

R and various installation packages: https://cran.r-project.org/

Http://cran.r-project.org/web/packages

R is a case-sensitive, interpreted language. You can enter and execute a command every time after the command prompt (>), or execute a set of commands written in the script file at once.

Most functions in R are provided by the program's built-in functions and user-defined functions (various installation packages).

The R statement is composed of functions and assignments. R uses <-instead of traditional = as an assignment symbol. Example: x<-5

Comments begin with the symbol #.

Function C () can combine its parameters into a single vector or list

2. Get Help

3. Working space

The Working space (workspace) is the current working environment for R, which stores all user-defined objects (vectors, matrices, functions, data frames, lists). At the end of an R session, you can save the current workspace to a mirror and load it automatically the next time you start R.

Working directory (working directory):

Save History Command record: SaveHistory () The default file name is. Rhistory, you can also name your own

Save the workspace (that is, include the R working environment to save all, the history can be executed as soon as you open it): Save.image () The default file name is. RData, you can also name your own

Read History command: loadhistory ("file name")

Read History workspace: Load ("file name") or simply double-click the file in the file directory

Note The default file name includes "."

Note: R in working directory path with forward slash/, backslash \ is escape character

Create a new working directory with the function dir.create ()

4. Input and output

Input: R environment Keyboard input, execute R language script in existing file

Output: Screen output, text output saved in a file

Input: The function source ("filename") is the R language script that executes in the current session that exists in the filename file. Either the file name contains a path, or the working directory is modified to the path where the file name resides. The result will appear on the screen.

Text output: Sink (): Returns output to the screen only;

Sink ("filename"): The output is redirected to the file filename, overwriting its contents;

Sink ("filename", append=true): Append to file after output, not overwrite;

Sink ("filename", split=true): Output is sent to both the screen and the file

Graphic output:

Finally, use Dev.off () to return the output to the terminal

5. Package

The storage directory that is wrapped on the computer is called a library. Install (download from a Cran mirror site and put into the library) before using the package, load (run the installed package)

Package Installation: Install.packages ("package name"), do not know the name of the package you want to install, the package name can be saved.

Update.packages () Update installed packages

Installed.packages () View details of installed packages

Package Loading: library (package name)

How to use the package: Help (package= "package name") can output a short description of a package and a list of function names and dataset names in the package.

Use the function help () to see more details about any of these functions or datasets.

Introduction to the R language

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.