This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
plot(cars)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
Giới thiệu đầu bài IRIS
Đoạn code load dữ liệu
#LOAD & INSTALL PACKAGE ----
install.packages("dplyr")
Installing package into ‘/cloud/lib/x86_64-pc-linux-gnu-library/4.3’
(as ‘lib’ is unspecified)
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/dplyr_1.1.2.tar.gz'
Content type 'application/x-gzip' length 1463430 bytes (1.4 MB)
==================================================
downloaded 1.4 MB
* installing *binary* package ‘dplyr’ ...
* DONE (dplyr)
The downloaded source packages are in
‘/tmp/RtmpftV05a/downloaded_packages’
install.packages("reshape2")
Installing package into ‘/cloud/lib/x86_64-pc-linux-gnu-library/4.3’
(as ‘lib’ is unspecified)
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/reshape2_1.4.4.tar.gz'
Content type 'application/x-gzip' length 116247 bytes (113 KB)
==================================================
downloaded 113 KB
* installing *binary* package ‘reshape2’ ...
* DONE (reshape2)
The downloaded source packages are in
‘/tmp/RtmpftV05a/downloaded_packages’
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
library(reshape2)
Dùng package Dplyr để tách bảng dữ liệu
#LOAD IRIS DATASET ----
data(iris)
head(iris,10)
tail(iris)
#STEP 1: EXPLORE DATA ----
summary(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 setosa :50
1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 versicolor:50
Median :5.800 Median :3.000 Median :4.350 Median :1.300 virginica :50
Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
dim(iris)
[1] 150 5
names(iris) <- tolower(names(iris))
class(iris)
[1] "data.frame"
typeof(iris$sepal.length)
[1] "double"
str(iris$sepal.length)
num [1:150] 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
str(iris$species)
Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...