\documentclass{beamer}
%\documentclass[handout]{beamer} aurait supprimé les ``overlays''

\usepackage{fancyvrb}
\usepackage{amsmath,amssymb}
\definecolor{midnightblue}{rgb}{0.098,0.098,0.439}

\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl,formatcom={\color{violet}}}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{,formatcom={\color{midnightblue}}}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl,formatcom={\color{violet}}}
\newenvironment{Schunk}{}{}
\DefineVerbatimEnvironment{Code}{Verbatim}{,formatcom={\color{violet}}}
\DefineVerbatimEnvironment{CodeInput}{Verbatim}{fontshape=sl,formatcom={\color{violet}}}
\DefineVerbatimEnvironment{CodeOutput}{Verbatim}{,formatcom={\color{midnightblue}}}
\newenvironment{CodeChunk}{}{}

\newcommand{\commande}[1]{\texttt{#1}}

\newcommand{\vide}[1]{}
\newtheorem{proposition}{Proposition}
\newcommand{\prob}{\text{\fontfamily{cmss}\fontseries{sbc}\fontshape{n}\selectfont P}}
\newcommand{\Prob}{\text{\fontfamily{cmss}\fontseries{sbc}\fontshape{n}\selectfont P}}
%\newcommand{\transp}{^{\text{\fontfamily{cmss}\fontseries{sbc}\fontshape{n}\selectfont T}}}
\newcommand{\transp}{^{\text{\fontfamily{cmss}\fontseries{m}\fontshape{n}\selectfont T}}}
\newcommand{\Log}{\rm Log}
\newcommand{\Argmax}{\rm Argmax}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\var}{\mathrm{var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\cov}{\mathrm{cov}}
\def\ind {\mbox {\rm 1\!\!\,l}}%fonction indicatrice

% \usepackage{pdfanim}
% \input{pdfanim-patch}
% \PDFAnimLoad[loop,remember,startframe=1,scaletype=A,height=100pt,width=150pt]{cloud}{balls}{10}

\usetheme{Warsaw}% le thème choisi pour ma présentation
\useoutertheme[hooks]{tree}
%\usecolortheme{seahorse}



\DeclareGraphicsRule{.pdftex}{pdf}{.pdftex}{}



\usepackage[french]{babel}
%\usepackage[latin1]{inputenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}%pour les includegraphics
\usepackage{array}% pour des tableaux particuliers. Nécessaire pour les révéler colonne par colonne
\usepackage{amsthm}
\usepackage{color}
%\usepackage{hyperref}
\usepackage{xspace} % rajouté le 25/05/2009
% On définit le symbole R
\newcommand{\R}{{\fontfamily{cmss}\fontseries{sbc}\fontshape{n}\selectfont R}\xspace}


\newtheorem{thm}{Théorème}
\newtheorem{result}{Résultat}
\newtheorem{boite}{}
\newtheorem{lemme}{Lemme}
\usepackage{bm,txfonts}
\newcommand{\gras}[1]{\ensuremath{\bm{\mathbf {#1}}}}

\newenvironment{cadre}[2]{%
\begin{center}%
$\text{ }$\\%
\fbox{$\text{ }$ $\text{ }$\parbox{0.9\textwidth}{%
$\text{ }$\\%
$\text{ }$\\%
#2%
$\text{ }$\\%
}$\text{ }$ $\text{ }$}
}{%
\end{center}%
}

\def\fleche{%
\begin{center}%
{\Huge \color{blue}$\Downarrow$\normalcolor}%
\end{center}}



\setbeamercovered{transparent}%l'autre option : invisible, cache totalement le texte pas encore découvert (ie, n'utilise pas le ``grisé'').

\colorlet{orange}{red!70!yellow}% mes petites couleurs que j'aime bien
\colorlet{mauve}{blue!70!red}
\colorlet{brouge}{red!70!blue}

\addtobeamertemplate{footline}{$\quad$\insertframenumber/\inserttotalframenumber\phantom{a}}
%pour ajouter un numéro de page en bas.
% une autre solution : \useoutertheme{shadow}


\title[Introductory course on the \R software]{Introductory course on the \R software}
%l'argument entre [] est une version courte du titre, qu'on met en bas des transparents.

\author[Lafaye de Micheaux, Pierre] % (optionnel, utiliser seulement s'il y a beaucoup d'auteurs)
{\textbf{P.~Lafaye de Micheaux}\inst{1}}


\institute[Départements et Universités] % (optionnel, mais nécessaire la plupart du temps)
{
  \inst{1}%
  	Mathematics and Statistics Departement\\
  	Université de Montréal\\
	CANADA
}

\date[2014]{New South Wales University\\
Sydney, Australia\\ May 13, 2014\\
\vspace{1ex}
\url{https://biostatisticien.eu/springeR/courseRw2.pdf}
}

%\AtBeginSection[] % pour mettre la table des matières 
%                 % au début de chaque section
%{ \begin{frame}<beamer> 
%\frametitle{Plan de la présentation} 
%\tableofcontents[currentsection] 
%\end{frame} }

 \pgfdeclareimage[height=96mm,width=128mm]{nombidon}{BatimentGIN}
  \setbeamertemplate{background}{\pgfuseimage{nombidon}}

% \logo{\includegraphics[width=1.5cm]{Rlogo.jpg}}% je définis le logo qui sera mis sur tous les transparents

\setbeamertemplate{background}{transparent}

\usepackage{ragged2e}
\justifying



\usepackage{algpseudocode,algorithm}


\RequirePackage{xcolor} 
\definecolor{beaubleu}{rgb}{0.26,0.31,0.61}
\definecolor{beauvert}{rgb}{0.27,0.52,0.42}


\usepackage{upquote}

\begin{document}


\begin{frame}
\titlepage


\vfill
\end{frame}

%\begin{frame}
%\tableofcontents[pausesections]
%\vspace*{\fill}
%\end{frame}



\section{Goals}



\begin{frame}
\frametitle{Goals of today lecture}

Introducing the
\begin{itemize}
\item basics concepts of the \R software:
\begin{itemize}
\item calculator mode
\item assignment operator
\item variables
\item functions
\item arguments
\end{itemize}
\item various data types and structures which can be handled by \R.
\end{itemize}

\end{frame}

\subsection{First session}


\begin{frame}[fragile]
\frametitle{\R is a calculator}

\R can easily replace all the functionalities of a (very sophisticated!) calculator.

\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ sin(2*pi/3)     # <--- this symbol is for comments.}
\textit{\textcolor{beauvert}{[1] 0.8660254}}
>\textcolor{beaubleu}{ 5^2             # Same as 5**2.}
\textit{\textcolor{beauvert}{[1] 25}}
>\textcolor{beaubleu}{ sqrt(4)         # Square root of 4.}
\textit{\textcolor{beauvert}{[1] 2}}
>\textcolor{beaubleu}{ log(1)          # Natural logarithm of 1.}
\textit{\textcolor{beauvert}{[1] 0}}
>\textcolor{beaubleu}{ c(1,2,3,4,5)    # Collection of the first 5 integers.}
\textit{\textcolor{beauvert}{[1] 1 2 3 4 5}}
>\textcolor{beaubleu}{ c(1,2,3,4,5)*2  # First five even numbers.}
\textit{\textcolor{beauvert}{[1]  2  4  6  8 10}}
\end{Verbatim}
\end{frame}


\begin{frame}[fragile]
\frametitle{Displaying results and variable redirecting}

\R responds to your requests by displaying the result obtained after evaluation. \textbf{But, this result is displayed, then lost.}\\


Nevertheless, we can use the \textbf{assignment arrows}: \texttt{<-} or \texttt{->}\\
$ $\\
\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ x <- 1      # Assignment.}
>\textcolor{beaubleu}{ x           # Display.}
\textit{\textcolor{beauvert}{[1] 1}}
>\textcolor{beaubleu}{ 2 -> x      # Assignment (in the other direction).}
>\textcolor{beaubleu}{ x           # Display.}
\textit{\textcolor{beauvert}{[1] 2}}
>\textcolor{beaubleu}{ (x <- 1)    # Assignment AND display.}
\textit{\textcolor{beauvert}{[1] 1}}
\end{Verbatim}


\begin{alertblock}{The \texttt{=} symbol}
It is not good practice to use the \texttt{=} symbol for assignment.
\end{alertblock}

\end{frame}

\begin{frame}[fragile]
\frametitle{Continuation symbol}

If a command is not complete at the end of a line, \R will display a different prompt symbol, by default the plus sign (\texttt{+}), on the second line and on following lines. \R will continue to wait for instructions until the command is syntactically complete.

\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ 2*8*10+exp(1)}
\textit{\textcolor{beauvert}{[1] 162.7183}}
>\textcolor{beaubleu}{ 2*8*}
+\textcolor{beaubleu}{ 10+exp(}
+\textcolor{beaubleu}{ 1)}
\textit{\textcolor{beauvert}{[1] 162.7183}}
\end{Verbatim}

\end{frame}



\begin{frame}[fragile]
\frametitle{Rules for choosing a variable name}



\begin{itemize}
\item a variable name can only include alphanumerical characters as well as the dot (.);
\item variable names are \textit{case sensitive}, which means that \R distinguishes upper and lower case;
\item a variable name may not include white space or start with a digit, unless it is enclosed in quotation marks \verb#""#.
\end{itemize}


\end{frame}

\begin{frame}
\frametitle{Work strategy}
You should use either a \textit{script window} (\textit{\R editor}) or Rstudio to type your commands before sending them to \R for execution.\\
$ $\\
The key combinations \texttt{CTRL+R} (or \texttt{CTRL+ENTER}) can be used to execute your commands.\\
$ $\\
You can also use the \texttt{source(file.choose())} command (typed in the \R console) to read and execute the contents of an external \R script file.\\
$ $\\
Note: The function \texttt{help()} can be used to access the documentation: \texttt{help(source)}.\\
$ $\\
\textbf{Perform the two ``Do it yourself'' on pages 42 and 43.}\\
\url{http://biostatisticien.eu/springeR/Rbook-chap3.pdf}


\end{frame}

\begin{frame}[containsverbatim]
\frametitle{Using functions}

A function in \R is defined by its \textbf{name} and by the list of its \textbf{parameters} (or \textbf{arguments}). 
Most functions output a \textbf{value}.\\
$ $\\
\textbf{Using} a function (or \textbf{calling} or \textbf{executing} it) is done by typing its name followed, in brackets, by the list of (formal) arguments to be used. Arguments are separated by commas. Each argument can be followed by the sign \verb#=# and the value to be given to the argument.\\


\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
\textcolor{beaubleu}{functionname(arg1=value1,arg2=value2,arg3=value3)}
\end{Verbatim}
Note that you do not necessarily need to indicate the names of the arguments, but only the values, as long as you follow their order.\\
For any \R function, some arguments must be specified and others are optional (because a default value is already given in the code of the function).\\


\end{frame}



\begin{frame}[fragile]
\frametitle{Understanding the use of arguments}
The function \texttt{log(x,base=exp(1))} can take two arguments:  \verb#x# (its value must be specified) and \verb#base# (optional, because a default value is provided as \texttt{exp(1)}).\\
$ $\\

\textbf{You can call a function by playing with the arguments in several different ways}. This is an important feature of \R which makes it easier to use.\\
$ $\\
\begin{minipage}[b]{0.5\linewidth}
\begin{tabular}{l}
\texttt{log(3)}\\
\texttt{log(x=3)}\\
\texttt{log(x=3,base=exp(1))}\\
\texttt{log(x=3,exp(1))}\\
\end{tabular}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.5\linewidth}
\begin{tabular}{l}
\texttt{log(3,base=exp(1))}\\
\texttt{log(3,exp(1))}\\
\texttt{log(base=exp(1),3)}\\
\texttt{log(base=exp(1),x=3)}\\
\end{tabular}
\end{minipage}
$ $\\
\textbf{Question: what is done with this instruction?} \begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
\textcolor{beaubleu}{log(exp(1),3)}
\end{Verbatim}


\end{frame}

\begin{frame}[containsverbatim]
\frametitle{Using functions}

\begin{alertblock}{Don't forget the brackets when you call a function}
A common mistake for beginners is forgetting the brackets:
\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ factorial # Typing the name gives the code.}
\textit{\textcolor{beauvert}{function (x) }}
\textit{\textcolor{beauvert}{gamma(x + 1)}}
\textit{\textcolor{beauvert}{<environment: namespace:base>}}
>\textcolor{beaubleu}{ factorial(6)}
\textit{\textcolor{beauvert}{[1] 720}}
>\textcolor{beaubleu}{ date}
\textit{\textcolor{beauvert}{function () }}
\textit{\textcolor{beauvert}{.Internal(date())}}
\textit{\textcolor{beauvert}{<environment: namespace:base>}}
>\textcolor{beaubleu}{ date() # Brackets are also necessary when}
>\textcolor{beaubleu}{        #  no arguments are required.}
\textit{\textcolor{beauvert}{[1] "Wed Jan  9 16:04:32 2013"}}
\end{Verbatim}

\end{alertblock}

\end{frame}


\begin{frame}[fragile]
\frametitle{Creating functions}

It is very easy to code a new function in \R, by using the function \texttt{function()}.\\
$ $\\
For example, here is how to code a function which takes two arguments $n$ and $p$  and calculates the binomial coefficient  $${n \choose p}=\frac{n!}{p!(n-p)!}$$
\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ binomial <- function(n,p) factorial(n)/(factorial(p)*}
+\textcolor{beaubleu}{                         factorial(n-p))}
\end{Verbatim}
$ $\\
You can now then use this new function as any other \R function:
\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ binomial(4,3)}
\textit{\textcolor{beauvert}{[1] 4}}
\end{Verbatim}

\end{frame}

\subsection{Data in \R}

\begin{frame}
\frametitle{The various data types in \R}

One of the main strengths of \R is its ability to organize data in a structured way. \textbf{This will turn out to be very useful for many statistical procedures.}

\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|}
\hline
\textbf{Data type} & \textbf{Type in \R} & \textbf{Display}\\
\hline
\hline
real number (integer or not) & \commande{numeric} & \texttt{3.27}\\
\hline
complex number & \commande{complex} & \texttt{3+2i}\\
\hline
logical (true/false) & \commande{logical} & \commande{TRUE} or \commande{FALSE}\\
\hline
missing &  \commande{logical} & \commande{NA}\\
\hline
text (string) & \commande{character} & \texttt{"text"}\\
\hline
binary & \commande{raw} & \texttt{1c}\\
\hline
\end{tabular}
\end{table}

\end{frame}



\begin{frame}[containsverbatim]
\frametitle{Dealing with data type}

\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ a <- 1 # Similar to: a <- 1.0}
>\textcolor{beaubleu}{ typeof(a)}
\textit{\textcolor{beauvert}{[1] "double"}}
>\textcolor{beaubleu}{ c <- as.integer(a)}
>\textcolor{beaubleu}{ typeof(c)}
\textit{\textcolor{beauvert}{[1] "integer"}}
>\textcolor{beaubleu}{ b <- 3.4}
>\textcolor{beaubleu}{ c(b>a,a==b)}
\textit{\textcolor{beauvert}{[1] TRUE FALSE}}
>\textcolor{beaubleu}{ is.numeric(a)}
\textit{\textcolor{beauvert}{[1] TRUE}}
>\textcolor{beaubleu}{ is.integer(a)}
\textit{\textcolor{beauvert}{[1] FALSE}}
>\textcolor{beaubleu}{ x <- TRUE # Similar to: x <- T}
>\textcolor{beaubleu}{ is.logical(x)}
\textit{\textcolor{beauvert}{[1] TRUE}}
\end{Verbatim}



\end{frame}

\begin{frame}[containsverbatim]
\frametitle{Missing data}

A missing\index{missing values} or undefined value is indicated by the instruction \commande{NA} (for \textit{non available}). 
\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ x <- c(3,NA,6)}
>\textcolor{beaubleu}{ is.na(x)}
\textit{\textcolor{beauvert}{[1] FALSE  TRUE FALSE}}
>\textcolor{beaubleu}{ mean(x)             # Let's try to calculate the mean.}
\textit{\textcolor{beauvert}{[1] NA}}
>\textcolor{beaubleu}{ mean(x,na.rm=TRUE)  # The na.rm argument indicates}
\textcolor{beaubleu}{                      # that NA's should be removed.}
\textit{\textcolor{beauvert}{[1] 4.5}}
\end{Verbatim}

\end{frame}

\begin{frame}[containsverbatim]
\frametitle{Character string type}

Any information between quotation marks (single \texttt{\textquotesingle} or double \commande{"}) corresponds to a character string\index{character strings}.

\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ a <- "R is my friend"}
>\textcolor{beaubleu}{ mode(a)}
\textit{\textcolor{beauvert}{[1] "character"}}
>\textcolor{beaubleu}{ is.character(a)}
\textit{\textcolor{beauvert}{[1] TRUE}}
\end{Verbatim}

\end{frame}

\begin{frame}
\frametitle{The various data structures in \R}
\begin{table}[H]
\centering
\scriptsize
\begin{tabular}{|c|c|p{4cm}|}
\hline
\textbf{Data structure} & \textbf{Instruction in \R} & \hspace*{2cm}\textbf{Description}\\
\hline
\hline
vector & \commande{c()} & Sequence of elements of the \textbf{same nature}. \\
\hline
matrix & \commande{matrix()} &   Two-dimensional table of elements of the \textbf{same nature}. \\
\hline
multidimensional table & \commande{array()} &  More general than a matrix; table with several dimensions. \\
\hline
list& \commande{list()} &  Sequence of \R structures of any (and possibly different) nature. \\
\hline
individual$\times$variable table & \commande{data.frame()} &  Two-dimensional table. The columns can be of different natures, but must have the same length.\\
\hline
factor &\commande{factor()}, \commande{ordered()} & Vector of character strings associated with a modality table.\\
\hline
dates & \commande{as.Date()} & Vector of dates.\\
\hline
time series & \commande{ts()} & Values of a variable observed at several time points.\\
\hline
\end{tabular}
\end{table}

\end{frame}

\begin{frame}[fragile]
\frametitle{Vectors}
\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ c(3,1,7)}
\textit{\textcolor{beauvert}{[1] 3 1 7}}
>\textcolor{beaubleu}{ c(3,TRUE,7) # Automatic conversion occurs.}
\textit{\textcolor{beauvert}{[1] 3 1 7}}
>\textcolor{beaubleu}{ seq(from=0,to=1,by=0.1)}
\textit{\textcolor{beauvert}{ [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0}}
>\textcolor{beaubleu}{ seq(from=0,to=20,length=5)}
\textit{\textcolor{beauvert}{[1]  0  5 10 15 20}}
>\textcolor{beaubleu}{ vec <- 1:10 # Stored as integers.}
>\textcolor{beaubleu}{ names(vec) <- letters[1:10]}
\textit{\textcolor{beauvert}{ a  b  c  d  e  f  g  h  i  j}}
\textit{\textcolor{beauvert}{ 1  2  3  4  5  6  7  8  9 10}}
>\textcolor{beaubleu}{ (vec <- 2:33) # \texttt{[17]} = rank of the next element.}
\textit{\textcolor{beauvert}{ [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17}}
\textit{\textcolor{beauvert}{[17] 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33}}
\end{Verbatim}

\end{frame}

\begin{frame}[fragile]
\frametitle{Matrices and arrays}
\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ ( X <- matrix(1:12,nrow=4,ncol=3,byrow=TRUE) )}
\textit{\textcolor{beauvert}{     [,1] [,2] [,3]}}
\textit{\textcolor{beauvert}{[1,]    1    2    3}}
\textit{\textcolor{beauvert}{[2,]    4    5    6}}
\textit{\textcolor{beauvert}{[3,]    7    8    9}}
\textit{\textcolor{beauvert}{[4,]   10   11   12}}
>\textcolor{beaubleu}{ class(X)}
\textit{\textcolor{beauvert}{[1] "matrix"}}
>\textcolor{beaubleu}{ X <- array(1:12,dim=c(2,2,3))}
\end{Verbatim}
 \centering\includegraphics[width=3cm]{array3d.png}

\end{frame}

\begin{frame}[fragile]
\frametitle{Lists: the most flexible and richest structure in \R}

Unlike the previous structures, lists can \textbf{group together in one structure data of different types} without altering them.
\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ ( A <- list(TRUE,-1:3,my.matrix=matrix(1:4,nrow=2),}
+\textcolor{beaubleu}{             c(1+2i,3),"A character string") )}
\textit{\textcolor{beauvert}{[[1]]}}
\textit{\textcolor{beauvert}{[1] TRUE}}
\textit{\textcolor{beauvert}{[[2]]}}
\textit{\textcolor{beauvert}{[1] -1  0  1  2  3}}
\textit{\textcolor{beauvert}{$my.matrix}}      Note: we have named this element of A.
\textit{\textcolor{beauvert}{     [,1] [,2]}}
\textit{\textcolor{beauvert}{[1,]    1    3}}
\textit{\textcolor{beauvert}{[2,]    2    4}}
\textit{\textcolor{beauvert}{[[4]]}}
\textit{\textcolor{beauvert}{[1] 1+2i 3+0i}}
\textit{\textcolor{beauvert}{[[5]]}}
\textit{\textcolor{beauvert}{[1] "A character string"}}
\end{Verbatim}

\end{frame}

\begin{frame}[fragile]
\frametitle{Data frames: most used structure in Statistics}

\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ ( BMI <- data.frame(Gender=c("M","F","M","F","M","F"),}
+\textcolor{beaubleu}{     Height=c(1.83,1.76,1.82,1.60,1.90,1.66),}
+\textcolor{beaubleu}{     Weight=c(67,58,66,48,75,55),row.names=c("Jack",}
+\textcolor{beaubleu}{     "Julia","Henry","Emma","William","Elsa")) )}
\textit{\textcolor{beauvert}{        Gender Height Weight}}
\textit{\textcolor{beauvert}{Jack         M   1.83     67}}
\textit{\textcolor{beauvert}{Julia        F   1.76     58}}
\textit{\textcolor{beauvert}{Henry        M   1.82     66}}
\textit{\textcolor{beauvert}{Emma         F   1.60     48}}
\textit{\textcolor{beauvert}{William      M   1.90     75}}
\textit{\textcolor{beauvert}{Elsa         F   1.66     55}}
>\textcolor{beaubleu}{ str(BMI) # Structure of each column.}
\textit{\textcolor{beauvert}{'data.frame':	6 obs. of  3 variables:}}
\textit{\textcolor{beauvert}{ $ Gender: Factor w/ 2 levels "F","M": 2 1 2 1 2 1}}
\textit{\textcolor{beauvert}{ $ Height: num  1.83 1.76 1.82 1.6 1.9 1.66}}
\textit{\textcolor{beauvert}{ $ Weight: num  67 58 66 48 75 55}}
\end{Verbatim}

\end{frame}

\begin{frame}[fragile]
\frametitle{Factors and ordinal variables}

\begin{Verbatim}[commandchars=\\\{\},fontfamily=courier,fontsize=\small,fontseries=b]
>\textcolor{beaubleu}{ x <- factor(c("blue","green","blue","red",}
+\textcolor{beaubleu}{                      "blue","green","green"))}
>\textcolor{beaubleu}{ x}
\textit{\textcolor{beauvert}{[1] blue  green blue  red   blue  green green}}
\textit{\textcolor{beauvert}{Levels: blue green red}}
>\textcolor{beaubleu}{ levels(x)}
\textit{\textcolor{beauvert}{[1] "blue"  "green" "red"  }}
>\textcolor{beaubleu}{ class(x)}
\textit{\textcolor{beauvert}{[1] "factor"}}
>\textcolor{beaubleu}{z<-ordered(c("Small","Tall","Average","Tall","Average",}
+\textcolor{beaubleu}{  "Small","Small"),levels=c("Small","Average","Tall"))}
>\textcolor{beaubleu}{ class(z)}
\textit{\textcolor{beauvert}{[1] "ordered" "factor" }}
\end{Verbatim}

\end{frame}

\begin{frame}
\frametitle{Your turn to work!}

You can now try to do the \textbf{Exercises} and the \textbf{Worksheet} of Chapter~3.\\
$ $\\
\url{http://biostatisticien.eu/springeR/Rbook-chap3.pdf}\\
$ $\\

\end{frame}

% \bibliographystyle{jss}
% \bibliography{biblio}

\end{document}

