library(readr)
## Warning: package 'readr' was built under R version 4.4.3
a <- read.csv("C:/Users/DELL/Downloads/World-Stock-Prices-Dataset.csv")
#Thông tin của dữ liệu
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.3
##
## 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(knitr,"\n\n")
## Warning: package 'knitr' was built under R version 4.4.3
# Số quan sát và số biến
cat("Số quan sát (dòng):", nrow(a), "\n")
## Số quan sát (dòng): 310122
cat("Số biến (cột):", ncol(a), "\n\n")
## Số biến (cột): 13
# Số quan sát trùng lặp
print("Đây là bảng tóm tắt kết quả",)
## [1] "Đây là bảng tóm tắt kết quả"
summary(a[c("Ticker", "Industry_Tag", "Country","Dividends","Stock.Splits","Capital.Gains")])
## Ticker Industry_Tag Country Dividends
## Length:310122 Length:310122 Length:310122 Min. : 0.000000
## Class :character Class :character Class :character 1st Qu.: 0.000000
## Mode :character Mode :character Mode :character Median : 0.000000
## Mean : 0.003643
## 3rd Qu.: 0.000000
## Max. :15.000000
##
## Stock.Splits Capital.Gains
## Min. :0.0e+00 Min. :0
## 1st Qu.:0.0e+00 1st Qu.:0
## Median :0.0e+00 Median :0
## Mean :8.7e-04 Mean :0
## 3rd Qu.:0.0e+00 3rd Qu.:0
## Max. :5.0e+01 Max. :0
## NA's :310120
# Số giá trị bị thiếu (NA) trong mỗi cột
cat("Số giá trị bị thiếu trong mỗi cột:\n")
## Số giá trị bị thiếu trong mỗi cột:
sapply(a, function(x) sum(is.na(x))) %>%
kable(col.names = "Số lượng NA")
Số lượng NA | |
---|---|
Date | 0 |
Open | 0 |
High | 0 |
Low | 0 |
Close | 0 |
Volume | 0 |
Brand_Name | 0 |
Ticker | 0 |
Industry_Tag | 0 |
Country | 0 |
Dividends | 0 |
Stock.Splits | 0 |
Capital.Gains | 310120 |
#Phân tổ các biến
df_categorized <- a %>%
mutate(
Price_Tier = case_when(
Close < 50 ~ "Giá thấp (<$50)",
Close >= 50 & Close <= 200 ~ "Giá trung bình ($50-$200)",
TRUE ~ "Giá cao (>$200)"
),
Liquidity_Tier = case_when(
Volume < 1000000 ~ "Thanh khoản thấp (<1M)",
Volume >= 1000000 & Volume <= 10000000 ~ "Thanh khoản trung bình (1M-10M)",
TRUE ~ "Thanh khoản cao (>10M)"
)
)
# Hiển thị các cột mới được tạo ra
df_categorized %>%
select(Brand_Name, Close, Price_Tier, Volume, Liquidity_Tier) %>%
head(10) %>%
kable(caption = "Dữ liệu sau khi thêm các biến phân loại")
Brand_Name | Close | Price_Tier | Volume | Liquidity_Tier |
---|---|---|---|---|
peloton | 6.64 | Giá thấp (<$50) | 4209664 | Thanh khoản trung bình (1M-10M) |
crocs | 107.34 | Giá trung bình ($50-$200) | 560190 | Thanh khoản thấp (<1M) |
adidas | 121.93 | Giá trung bình ($50-$200) | 36600 | Thanh khoản thấp (<1M) |
amazon | 223.41 | Giá cao (>$200) | 29295154 | Thanh khoản cao (>10M) |
apple | 213.55 | Giá cao (>$200) | 34697317 | Thanh khoản cao (>10M) |
nike | 76.39 | Giá trung bình ($50-$200) | 11545304 | Thanh khoản cao (>10M) |
target | 104.06 | Giá trung bình ($50-$200) | 3535290 | Thanh khoản trung bình (1M-10M) |
179.53 | Giá trung bình ($50-$200) | 21563145 | Thanh khoản cao (>10M) | |
spotify | 725.05 | Giá cao (>$200) | 1071771 | Thanh khoản trung bình (1M-10M) |
zoom video communications | 78.58 | Giá trung bình ($50-$200) | 2882442 | Thanh khoản trung bình (1M-10M) |
table(cut(a$Volume, 3))
##
## (-7.42e+06,2.47e+09] (2.47e+09,4.95e+09] (4.95e+09,7.43e+09]
## 310110 11 1
#Bảng tóm tắt
# xem tóm tắt
print("Đây là bảng **tóm tắt kết** quả" )
## [1] "Đây là bảng **tóm tắt kết** quả"
summary(a[c("Open", "High", "Low","Close")])
## Open High Low Close
## Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.199
## 1st Qu.: 15.93 1st Qu.: 16.16 1st Qu.: 15.71 1st Qu.: 15.940
## Median : 35.41 Median : 35.81 Median : 34.98 Median : 35.408
## Mean : 76.33 Mean : 77.20 Mean : 75.44 Mean : 76.338
## 3rd Qu.: 84.00 3rd Qu.: 84.92 3rd Qu.: 83.09 3rd Qu.: 84.000
## Max. :3445.58 Max. :3463.07 Max. :3370.00 Max. :3427.610
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)
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.