sudo apt-get install r-base

setwd()
getwd()

R may be used like a simple calculator. Type the following command in front of the prompt and hit .

2 + 3
2 / 3
2 * 3
2 - 3


2/0

Guess the result of

2/Inf

Inf/Inf

So now you know about three different types of `numbers' that R can handle: ordinary numbers, infinities, NaN (Not a Number).

R can work with variables. For example

x = 4

assigns the value 4 to the variable x. This assignment occurs silently, so you do not see any visible effect immediately. To see the value of x type

x

Let us create a new variable

y = -4

x + y
x - 2*y
x^2 + 1/y

z-2*x

X + Y

Well, I should have told you already: R is case sensitive!

x = 2*x

	
Unlike many other languages, R allows the dot character (.) as part of a variable name. Thus you can write

speed.light = 3e8 # 300 000 000 m/s

Standard functions

R knows most of the standard functions.


sin(x)
cos(0)
sin(pi) #pi is a built-in constant
tan(pi/2)

	
exp(1)
log(3)
log(-3)
log(0)
log(x-y)

What is the base of the logarithm?

R has many many features and it is impossible to keep all its nuances in one's head. So R has an efficient online help system. The next exercise introduces you to this.


?log

Always look up the help of anything that does not seem clear. The technique is to type a question mark followed by the name of the thing you are interested in. All words written like this in this tutorial have online help.	

Sometimes, you may not know the exact name of the function that you are interested in. Then you can try the help.search function. It has a useful abbreviation:

help.search("sin")

can be contracted to

??sin

Gamma(2)

Oops! Apparently this is not the Gamma function you are looking for. So try

help.search("Gamma")

This will list all the topics that involve Gamma. After some deliberation you can see that ``Special Functions of Mathematics'' matches your need most closely. So type

?Special

Got the information you needed?

Searching for functions with names known only approximately is often frustrating.
