-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lecture-06 Description and Statistics of Data in R Envrionment.R
171 lines (95 loc) · 3.61 KB
/
Lecture-06 Description and Statistics of Data in R Envrionment.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
################################################################################
# &&&....&&& % Learning R Course in Summer of 2022 #
# &&&&&&..&&&&&& % Teacher: Bo Li, Mingwei Liu #
# &&&&&&&&&&&&&& % Date: Jul. 05th, 2022 #
# &&&&&&&&&&&& % #
# &&&&&&&& % Environment: R version 4.1.1; #
# &&&& % Platform: x86_64-w64-mingw32/x64 (64-bit) #
# & % #
################################################################################
################################################################################
### code chunk number 05: Installing & Running R Language.
################################################################################
### ****************************************************************************
### Step-01. About working directory in R.
# For windows, work directory.
pri.dir <- getwd()
setwd("D:/00-GitHub/LRC/tmp/")
### End of Step-01.
### ****************************************************************************
### ****************************************************************************
### Step-02. mean(), median().
# 1) Mean.
x <- c(1:10)
av <- mean(x)
print(av)
x[3] <- NA
print(x)
av1 <- mean(x, na.rm = TRUE)
print(av1)
?mean # remove
# 2) Median.
mv <- median(x)
print(mv)
# 3) fivenum
x <- 1:10
fivenum(x)
summary(x)
# 4) var, sd
var(x)
x1 <- var(x)
x1^0.5
sd(x)
# 5) data distribution
x <- 1:1000
hist(x)
x1 <- rnorm(1000, mean = 5, sd = 1)
mean(x1); sd(x1); var(x1)
hist(x1, breaks = 100) # 直方图
hist(x1, breaks = 30, probability = TRUE)
lines(density(x1), col = "red", lwd = 3)
### End of Step-02.
### ****************************************************************************
x1
quantile(x1)
median(x1)
quantile(x1)[3] == median(x1)
boxplot(x1) # 触须
quantile(x1, 0.75) - quantile(x1, 0.25) # !!!
IQR(x1)
range(x1)
#
e <- c(2.1, 2.0, 1.9, 4.5, 2.2, 2.3, 1.89, 23, 2.0, 2.01)
te1 <- mean(e)
te2 <- median(e)
te3 <- mean(e[c(-4, -8)])
print(te3)
boxplot(e)
### ****************************************************************************
### Step-03. Skewness and kurtosis.
# 1) Installing the related R package.
install.packages("fBasics")
# 2) Computing the statistics.
### End of Step-03.
### ****************************************************************************
### ****************************************************************************
### Step-04. Reading and writing xlsx format files.
# 1) Reading the xlsx files.
# 2) Writing the xlsx files.
### End of Step-04.
### ****************************************************************************
### ****************************************************************************
### Step-05. Reading and writing XML format files.
# 1) Reading the XML files.
# 2) Writing the XML files.
### End of Step-05.
### ****************************************************************************
### ****************************************************************************
### Step-06. Reading and writing json format files.
# 1) Reading the json files.
# 2) Writing the json files.
### End of Step-06.
### ****************************************************************************
################################################################################
### End of chunk-01.
################################################################################