Database Reference
In-Depth Information
Quick and Dirty Essentials of R
Upon starting R, you will see a prompt describing the version of R you are accessing, a dis-
claimer about R as a free software, and some functions regarding license, contributors, and
demos of R.
R uses an interactive shell—each line is interpreted after you hit return. A > prompt appears
when R is ready for another command. In this topic, all commands that a user enters appear in
bold after the prompt.
Built-in functions and simple mathematical calculations are the basics of R language. By typ-
ing 1+1 and hitting Enter, you'll observe the following:
> 1+1
[1] 2
> myAnswer<-sqrt(81)
> myAnswer
[1] 9
Just like a calculator, you can also take logs with log() , find the sin of angles with sin() ,
and take absolute values of any real number with abs() . R allows you to store your results
in a variable by using the <- operator. To view the value of a variable, simply type its name.
Names in R are case-sensitive, so one, One, and oNe are three different variables. You can
also create a vector (a collection of elements) using variables of the same type ( int , num , etc):
> x<-c(0,1,2,3) # R treats everything behind the pound sign as comments x [1] 0 1 2 3
> x[1] #access to the first element of the vector [1] 0
To view the internal help page for a unfamiliar function, type the keyword with ? . It will
provide a detailed description of the function, its parameters, its outputs, and is generally fol-
lowed by a simple example using the function. You can also type help.search() to determ-
ine if there is a function that will perform what you desire.
> ?mean
> help.search(mean)
Search WWH ::




Custom Search