-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchapitre_03.R
103 lines (83 loc) · 1.65 KB
/
chapitre_03.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Les types de données
## Le type `numeric`
nbrRep <- 5
typeof(nbrRep)
typeof(5.32)
is.numeric(5)
is.double(5)
nbrRep <- as.integer(5)
typeof(nbrRep)
typeof(5.32)
typeof(as.integer(5.32))
as.integer(5.32)
as.integer(5.99)
is.numeric(nbrRep)
is.integer(5)
is.numeric(5)
is.integer(as.integer(5))
is.numeric(as.integer(5))
sumIntDou <- as.integer(5) + 5.2
typeof(sumIntDou)
sumIntInt <- as.integer(5) + as.integer(5)
typeof(sumIntInt)
roundDou <- round(5.2)
typeof(roundDou)
## Le type `character`
myText <- "azerty"
myText2 <- 'azerty'
myText3 <- 'azerty uiop qsdfg hjklm'
typeof(myText3)
myText <- "a 'ze' 'rt' y"
myText2 <- 'a "zert" y'
myText3 <- 'azerty uiop qsdfg hjklm'
myText4 <- "qwerty \" azerty "
myText5 <- "qwerty \\ azerty "
myText <- "a 'ze' 'rt' y"
myText
myText <- "a 'ze' 'rt' y"
print(myText)
nbrRep <- 5
print(nbrRep)
print(myText2)
print(myText3)
print(myText4)
print(myText5)
myText <- "qwerty"
typeof(myText)
myText2 <- 5 # ceci n'est pas du texte
typeof(myText2)
myText3 <- "5"
typeof(myText3)
myText2 + 10
as.character(5)
# myText3 + 10
# Error in myText3 + 10 : non-numeric argument to binary operator
# "a" + "b"
# Error in "a" + "b" : non-numeric argument to binary operator
## Le type `factor`
factor01 <- factor("aaa")
print(factor01)
typeof(factor01)
is.factor(factor01)
levels(factor01)
factor01 <- factor("aaa")
as.character(factor01)
as.numeric(factor01)
## Le type `logical`
aLogic <- TRUE
print(aLogic)
typeof(aLogic)
is.logical(aLogic)
aLogic + 1
as.numeric(aLogic)
as.character(aLogic)
## A propos de `NA`
print(NA)
typeof(NA)
typeof(as.integer(NA))
typeof(as.character(NA))
NA == TRUE
NA == FALSE
NA > 1
NA + 1
## Conclusion