Sunteți pe pagina 1din 2

Hello, and welcome to Programming in R.

R is a programming language and software


environment
for statistical computing and graphics. What we are to tell you about in this
online course
is, well, not the programming language itself, but how to program in it, and how to
do graphics.
We will access R through the command prompt. This is the Microsoft R Open GUI. You
can
follow these sessions using your favorite user interface to R, as we will only work
with commands submitted to R through the command prompt. There are normally many
ways to do
that, and GUIs gives you ways of submitting code from an R script to the command
prompt.
In this GUI, you mark the code in a script and press "Control-R", and the code is
copied
to the command prompt and executed.
You can also write directly in the command prompt.
Let's us have a look at what a command to the R system looks like. The first line
on
this slide simulates 100 normally distributed random numbers, and store them in the
object
x. Do not worry about the syntax and command structure at this point, we will come
back
to assigning values shortly, and simulation later in the course. What the top line
does
is that it creates an object 'x' which is stored in the R memory, and which can be
referred
to. When I refer to 'x' as an object, it is on purpose. R is an object oriented
programming
environment, much more than most other statistical software packages.
Let us investigate the object x with some of the features of R. We can refer
directly
to x through its identifier, which is the symbol 'x'. We know that x consists of
100
numbers, let us look at how they look like. We can do that with the 'head' command.
When
the command is entered into the R command prompt, the result is displayed on the
screen.
'head' displays the first 6 elements of the object x. Pay attention to the numbers
in
square brackets. They are not themselves part of the object x, but indicate the
number of
the first element in each row, so that row 1 of the output starts with element
number
1, while the second row starts with element number 5. This may not be the same with
your
own version of R, perhaps because your command window is not of the same size as
ours. Also,
try to enlarge your command window and run the heads command again. If you have
enlarged
the command window sufficiently, you will only get one line of output rather than
two,
and therefore only one number in square brackets. Now, back to the output: head(x)
shows 6 numbers
with 8 digits after the decimal point, the first 6 elements of x. Perhaps you
wonder
if you can write 'tail', just as you write 'head'. Yes you can, and 'tail' does
what
you think it does.
There are other ways to investigate the object x: Using appropriate functions, we
can extract
the mean, standard deviation, minimum and maximum of the 100 numbers that
constitute
the object x. Pay attention to that the output from applying all of these functions
are printed
on the screen with a "1" in square brackets, because the output themselves are R
objects
of length 1.
Now, take some time to complete the first exercise.

S-ar putea să vă placă și