====== Installation, base ======
__Windows__
  - Open http://www.r-project.org/ in your browser.
  - Click on “CRAN”. You’ll see a list of mirror sites, organized by country.
  - Select a site near you.
  - Click on “Windows” under “Download and Install R”.
  - Click on “base”.
  - Click on the link for downloading the latest version of R (an .exe file).
  - When the download completes, double-click on the .exe file and answer the usual questions.
__OS X__
  - Open http://www.r-project.org/ in your browser.
  - Click on “CRAN”. You’ll see a list of mirror sites, organized by country.
  - Select a site near you.
  - Click on “MacOS X”.
  - Click on the .pkg file for the latest version of R, under “Files:”, to download it.
  - When the download completes, double-click on the .pkg file and answer the usual questions.
__Linux or Unix__
The major Linux distributions have packages for installing R. Here are some examples:
^ Distribution  ^ Package name  ^
| Ubuntu or Debian  | r-base  |
| Red Hat or Fedora  | R.i386  |
| Suse  | R-base  |
Use the system’s package manager to download and install the package. Normally, you will need the root password or sudo privileges; otherwise, ask a system administrator to perform the installation.
====== Rstudio ======
[[https://www.rstudio.com/|Rstudio as a R tool]]
[[https://www.rstudio.com/products/rstudio/download/#download|download]] for windows OS.
====== Starting R ======
__Windows__
  * Click on Start → All Programs → R; or 
  * double-click on the R icon on your desktop (assuming the installer created an icon for you). 
__OS X__ 
  * Either click on the icon in the Applications directory or 
  * put the R icon on the dock and click on the icon there. 
  * Alternatively, you can just type R on a Unix command line in a shell. 
__Linux or Unix__ 
  * Start the R program from the shell prompt using the R command (uppercase R). 
====== A trial ======
install.packages("NRAIA")
library(NRAIA)
detach(package:NRAIA)
trees
summary(trees)
boxplot(trees)
pair(trees)
cars
plot(dist~speed, data=cars)
m.cars <- lm(dist ~ speed, data=cars)
m.cars
summary(m.cars)
chickwts
summary(chickwts)
boxplot(weight~feed, data=chickwts)
anova(lm(weight~feed, data=chickwts) ## or . . . 
m.chck <- aov(weight~feed, data = chickwts)
m.chck
summary(m.chck)
[[:t-test]]
[[:ANOVA]]
[[:Factorial ANOVA]]
[[:correlation]]
[[:regression]]
[[:Multiple regression]]
====== Entering commands ======
> 1+1
> 1+1
[1] 2
max(1,3,5) 
[1] 5 
max(1,3
,5) 
[1] 5 
Table 1-1. Keystrokes for command-line editing 
^ Labeled key  ^ Ctrl-key combination  ^ Effect  ^ 
| Up arrow  | Ctrl-P  | Recall previous command by moving backward through the history of commands.   |
| Down arrow  | Ctrl-N  | Move forward through the history of commands.   |
| Backspace  | Ctrl-H  | Delete the character to the left of cursor.   |
| Delete (Del)  | Ctrl-D  | Delete the character to the right of cursor.   |
| Home  | Ctrl-A  | Move cursor to the start of the line.   |
| End  | Ctrl-E  | Move cursor to the end of the line.   |
| Right arrow  | Ctrl-F  | Move cursor right (forward) one character.   |
| Left arrow  | Ctrl-B  | Move cursor left (back) one character.   |
|   | Ctrl-K  | Delete everything from the cursor position to the end of the line.   |
|   | Ctrl-U  | Clear the whole darn line and start over.  |
| Tab  |   | Name completion (on some platforms).  |
====== Exiting from R ======
On all platforms, you can also use the q function (as in quit) to terminate the program. 
> q() 
Note the empty parentheses, which are necessary to call the function. 
__Windows__ 
  * Select File → Exit from the main menu; or click on the red X in the upper-right corner of the window frame.
__OS X__ 
  * Press CMD-q (apple-q); or click on the red X in the upper-left corner of the window frame. 
__Linux or Unix__ 
  * At the command prompt, press Ctrl-D. 
====== Getting help ======
Use the help.start function to see the documentation’s table of contents: 
 > help.start() 
 > help.start()
starting httpd help server ... done
If nothing happens, you should open
‘http://127.0.0.1:25578/doc/html/index.html’ yourself
{{r:r_help.start.jpg?500|start.help()}}
//__Packages__//
Click here to see a list of all the installed packages, both in the base packages and the additional, installed packages. Click on a package name to see a list of its functions and datasets.
//__Search Engine & Keywords__//
Click here to access a simple search engine, which allows you to search the documentation by keyword or phrase. There is also a list of common keywords, organized by topic; click one to see the associated pages.
====== Getting help from functions ======
Use help to display the documentation for the function:
 > help(functionname) 
Use args for a quick reminder of the function arguments:
 > args(functionname) 
Use example to see examples of using the function:
 > example(functionname) 
 > help(mean) 
 > ?mean 
 > args(mean) 
 > example(mean) 
 > > example(mean)
mean> x <- c(0:10, 50)
mean> xm <- mean(x)
mean> c(xm, mean(x, trim = 0.10))
[1] 8.75 5.50
see [[https://3months.tistory.com/97|this document]] for **trim** option
 mean> mean(USArrests, trim = 0.2)
Murder Assault UrbanPop Rape
7.42 167.60 66.20 20.16
 mean> colMeans(USArrests)
Murder Assault UrbanPop Rape
7.42 167.60 66.20 20.16
see [[https://rfriend.tistory.com/40|this document]] for **colMeans** function.
====== Searching via Keywords ======
 > help.search("pattern") 
  * A typical pattern is a function name or keyword. 
  * Notice that it must be enclosed in quotation marks.
 > ??pattern 
 > help.search("social network") 
====== Getting help on a package ======
 > help(package="packagename") 
 > help(package="tseries") 
 > install.package("tseries")
Error: could not find function "install.package"
 > install.packages("tseries")
Installing package into ‘D:/Users/Hyo/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://cran.ism.ac.jp/bin/windows/contrib/3.2/tseries_0.10-35.zip'
Content type 'application/zip' length 321067 bytes (313 KB)
downloaded 313 KB
package ‘tseries’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
        C:\Users\Hyo\AppData\Local\Temp\RtmpmQCQRK\downloaded_packages
> help(package="tseries")
> 
{{help.package.jpg}}
====== Searching the Web for help ======
 > RSiteSearch("ANOVA") 
====== Finding Relevant Functions and Packages ======
  * Visit the list of task views at http://cran.r-project.org/web/views/. Find and read the task view for your area, which will give you links to and descriptions of relevant packages. Or visit http://rseek.org, search by keyword, click on the Task Views tab, and select an applicable task view.
  * Visit [[http://crantastic.org/|crantastic]] and search for packages by keyword.
  * To find relevant functions, visit http://rseek.org, search by name or keyword, and click on the Functions tab.