##Nomination des variables

AAA<-10
aaa<-5
Aaa<-2
##Afficahge des variables
AAA
## [1] 10
aaa
## [1] 5
Aaa
## [1] 2

Cette partie appelle AAA

AAA
## [1] 10

Cette partie appelle AAA

aaa
## [1] 5

Cette partie appelle AAA

## [1] 2

Bonjour j’écris mon premier vecteur

v<-c(1,2,5,8,9)

L’affichage du mode et la longueur du vecteur v

v<-c(1,2,5,8,9)
m<-mode(v)
m
## [1] "numeric"
a<-"le mode de v est" 
b<-c(a,m)
b
## [1] "le mode de v est" "numeric"
length(v)
## [1] 5

Bonjour Je veux afficher les trois premières lignes de car

head(cars, n=3L)
##   speed dist
## 1     4    2
## 2     4   10
## 3     7    4

La longueur d’une chaine de caractère

v1<-"Bonjour"
v2<-c("B","o","n","j","o","u","r")
length(v1)
## [1] 1
length(v2)
## [1] 7
nchar(v1)
## [1] 7
nchar(v2)
## [1] 1 1 1 1 1 1 1
seq(1,5, by=0.1)
##  [1] 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8
## [20] 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7
## [39] 4.8 4.9 5.0

##Mercredi 10-07-2024: MATRICES

y<- matrix(c(2,3,5,8,9,6,2,4,8),ncol=2,byrow=T)
## Warning in matrix(c(2, 3, 5, 8, 9, 6, 2, 4, 8), ncol = 2, byrow = T): data
## length [9] is not a sub-multiple or multiple of the number of rows [5]
y
##      [,1] [,2]
## [1,]    2    3
## [2,]    5    8
## [3,]    9    6
## [4,]    2    4
## [5,]    8    2

##Indice d’un vecteur et d’une matrice

Vect<-c(1.5:10.5)
Vect
##  [1]  1.5  2.5  3.5  4.5  5.5  6.5  7.5  8.5  9.5 10.5
matrix<-matrix(Vect, nrow =3, ncol =3)
## Warning in matrix(Vect, nrow = 3, ncol = 3): data length [10] is not a
## sub-multiple or multiple of the number of rows [3]
matrix
##      [,1] [,2] [,3]
## [1,]  1.5  4.5  7.5
## [2,]  2.5  5.5  8.5
## [3,]  3.5  6.5  9.5
matrix[2:3,c(1,3)]
##      [,1] [,2]
## [1,]  2.5  8.5
## [2,]  3.5  9.5
S_ligne<-apply(matrix(1,2),1,sum)

##Opéraations sur les matrices

x<-c(1:5)
x
## [1] 1 2 3 4 5
y<-c(rep(0,3),rep(1,2))
y
## [1] 0 0 0 1 1
x+y
## [1] 1 2 3 5 6
x-y
## [1] 1 2 3 3 4
x*y
## [1] 0 0 0 4 5
matrix
##      [,1] [,2] [,3]
## [1,]  1.5  4.5  7.5
## [2,]  2.5  5.5  8.5
## [3,]  3.5  6.5  9.5
apply(matrix,1,diff)
##      [,1] [,2] [,3]
## [1,]    3    3    3
## [2,]    3    3    3

##FACTOR

l<-c(1,2,3)
f<-as.factor(l)
f
## [1] 1 2 3
## Levels: 1 2 3
is(f)
## [1] "factor"              "integer"             "oldClass"           
## [4] "double"              "numeric"             "vector"             
## [7] "data.frameRowLabels"
state<-c("bonjour","bonsoir","bonmidi","bonnenuit","bonretour","bonnearrivee","bonsoir","bonmidi","bonretour","bonnearrivee","bonjour","bonsoir","bonmidi","bonnenuit","bonretour","bonnearrivee","bonjour","bonsoir","bonmidi","bonnenuit","bonretour")
state
##  [1] "bonjour"      "bonsoir"      "bonmidi"      "bonnenuit"    "bonretour"   
##  [6] "bonnearrivee" "bonsoir"      "bonmidi"      "bonretour"    "bonnearrivee"
## [11] "bonjour"      "bonsoir"      "bonmidi"      "bonnenuit"    "bonretour"   
## [16] "bonnearrivee" "bonjour"      "bonsoir"      "bonmidi"      "bonnenuit"   
## [21] "bonretour"
statef<-factor(state)
statef
##  [1] bonjour      bonsoir      bonmidi      bonnenuit    bonretour   
##  [6] bonnearrivee bonsoir      bonmidi      bonretour    bonnearrivee
## [11] bonjour      bonsoir      bonmidi      bonnenuit    bonretour   
## [16] bonnearrivee bonjour      bonsoir      bonmidi      bonnenuit   
## [21] bonretour   
## Levels: bonjour bonmidi bonnearrivee bonnenuit bonretour bonsoir
revenue<-c(25,23,10,12,18,25,100,76,56,35,48,89,202,350,86,36,85,23,5,6,5)
revenue_moyen<-tapply(revenue,state,var)
revenue_moyen
##      bonjour      bonmidi bonnearrivee    bonnenuit    bonretour      bonsoir 
##     916.3333    8414.2500      37.0000   38769.3333    1358.2500    1724.2500

##Listes

rdn=list(serire=c(1:100))
rdn
## $serire
##   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
##  [19]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
##  [37]  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54
##  [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72
##  [73]  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
##  [91]  91  92  93  94  95  96  97  98  99 100
v1 <- c(1,2,3)
v2 <- c(4,3,2)
vt <- c("a","b","c","d")
m <- matrix(c(1,2,3,4,5,6), nrow = 2, ncol = 3, byrow = TRUE)
l1 <- list(v1,v2) # Crée la liste avec les objets v1 et v2
vt
## [1] "a" "b" "c" "d"
l1
## [[1]]
## [1] 1 2 3
## 
## [[2]]
## [1] 4 3 2
 names(l1) # Les éléments ne sont pas nommés
## NULL
 names(l1) <- c("v1","v2")

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.