文档介绍:Introduction To R
What is R?
The R statistical programming language is a free open source package based on the S language developed by Bell Labs.
The language is very powerful for writing programs.
Many statistical functions are already built in.
Contributed packages expand the functionality to cutting edge research.
Since it is a programming language, puter code plete tasks is required.
Getting Started
Where to get R?
Go to .org
Downloads: CRAN
Set your Mirror: Anyone in the USA is fine.
Select Windows 95 or later.
Select base.
Select R--
The others are if you are a developer and wish to change the source code.
UNT course website for R:
/
Getting Started
The R GUI?
Getting Started
Opening a script.
This gives you a script window.
Getting Started
Basic assignment and operations.
Arithmetic Operations:
+, -, *, /, ^ are the standard arithmetic operators.
Matrix Arithmetic.
* is element wise multiplication
%*% is matrix multiplication
Assignment
To assign a value to a variable use “<-”
Getting Started
How to use help in R?
R has a very good help system built in.
If you know which function you want help with simply use ?_______ with the function in the blank.
Ex: ?hist.
If you don’t know which function to use, then use (“_______”).
Ex: (“histogram”).
Importing Data
How do we get data into R?
Remember we have no point and click…
First make sure your data is in an easy to read format such as CSV (Comma Separated Values).
Use code:
D <- (“path”,sep=“,”,header=TRUE)
Working with data.
Accessing columns.
D has our data in it…. But you can’t see it directly.
To select a column use D$column.
Working with data.
Subsetting data.
Use a logical operator to do this.
==, >, <, <=, >=, <> are all logical operators.
Note that the “equals” logical operator is two = signs.
Example:
D[D$Gender == “M”,]
This will return the rows of D where Gender is “M”.
Remember R is case sensitive!
This code does noth