Introduction to R - Introduzione a R

The first session with R

Now double click on the R icon and follow the tutorial by typing commands as shown below, on the R console.
We can start using R as a calculator

> 2+2
[1] 4

The standard assignment operator in R is > − or =. You can use both symbols indiscriminately.
R works using objects and it is case sensitive, then an object named a and an object named A, are two different things. If we type the name of an object that has not already been created we get an error message telling us that the object does not exist in the current work space.

> a=2+2
> a
[1] 4
> b=2*a

In R most of the work is going to be organized as follows:

  1. Open the R console.
  2. Read data into the work space.
  3. Start elaborations and as the work proceeds, save effective commands into a script.
  4. Save data and elaboration together with the script file in a working directory.

The script file is a simple text file that will contain all the commands necessary to perform the desired task on the data. It can be opened into the R work session using the R internal editor. From the editor it is possible to directly select and execute command lines. In the windows installation this is obtain using ctrl+r and in the MacOs using cmd+enter. It is useful to write comments in the script file so to keep track of the analysis and to ease the file readability. To write comments in the command script we use the symbol # , any word written after # will not be executed.

La prima sessione con R

Per lanciare R fare doppio click sull'icona di R, si segua il tutorial digitando i comandi che seguono nella console di R.
Uso di R come calcolatrice

> 2+2
[1] 4

L'operatore di assegnazione in R é > − or =. Si possono usare indistintamente entrambi.
R usa gli oggetti ed distingue le maiuscole dalle minuscole (case-sensitive), quindi un oggetto chiamato a e un oggetto chiamato A, sono due oggetti differenti. Se si digita il nome di un oggetto che non é stato ancora creato si otterá un errore che indica che l'oggetto richiesto non esiste nello spazio di lavoro corrente.

> a=2+2
> a
[1] 4
> b=2*a

La maggior parte del lavoro in R sará organizzato nel seguente modo:

  1. Si apre la console di R.
  2. Si importano i dati nello spazio di lavoro.
  3. Si effettuano le elaborazioni e man mano che il lavoro procede, si salvano i comandi efficaci un file di script.
  4. Infine si salvano i dati e le elaborazioni insieme in un file di script in una directory di lavoro.

Il file di script é un semplice file di testo contenete tutti i comandi necessari per eseguire una determinata elaborazione sui dati. Puó essere modificato dalla sessione di lavoro di R con l'editor interno di R. Dall'editoe é possibile selezionare direttamente ed eseguire righe di comando. Nell'installazione di Windows si usa ctrl+r e in quella di MacOs si usa cmd+enter. É utile aggiungere dei commenti nello script in modo da tenere traccia dell'analisi e per facilitare la leggibilitá del file. Per inserire dei commenti nello script dei comandi si usa il simbolo #, qualunque parola scritta dopo # non sará eseguita.