DAY 10
0
AI & Data

## [Data Science系列]利用R語言處理更多資料-利用data.frame優化恩君的交友平台

``````na <- c("Billy", "Bloodhoof", "Scars", "Dean", "Sammy")
ra <- c("Orc", "Hoblin", "Goblin", "Elf", "Harpy")
sa <- c(120, 88, 50, 190, 166)
we <- factor(c("OK", "POOR", "POOR", "RICH", "RICH" ), ordered = TRUE, levels = c("POOR", "OK", "RICH"))

print(村莊狀態)
名字   種族 儲蓄 富有度
1     Billy    Orc  120     OK
2 Bloodhoof Hoblin   88   POOR
3     Scars Goblin   50   POOR
4      Dean    Elf  190   RICH
5     Sammy  Harpy  166   RICH
``````

``````tail(村莊狀態)
``````

``````dim(村莊狀態)
[1] 5 4
``````

5代表共5筆，
5代表共5筆觀測值（Observations，Obs）來稱呼資料框中水平方向的資料，4代表變數（Variables）來稱呼資料框中垂直方向的資料。

``````str(村莊狀態)
'data.frame':	5 obs. of  4 variables:
\$ 名字  : Factor w/ 5 levels "Billy","Bloodhoof",..: 1 2 5 3 4
\$ 種族  : Factor w/ 5 levels "Elf","Goblin",..: 5 4 2 1 3
\$ 儲蓄  : num  120 88 50 190 166
\$ 富有度: Ord.factor w/ 3 levels "POOR"<"OK"<"RICH": 2 1 1 3 3
``````

``````na <- c("Billy", "Bloodhoof", "Scars", "Dean", "Sammy")

str(na)
chr [1:5] "Billy" "Bloodhoof" "Scars" "Dean" "Sammy"
``````

``````ra_factor <- as.factor(ra)

'data.frame':	5 obs. of  4 variables:
\$ 名字  : chr  "Billy" "Bloodhoof" "Scars" "Dean" ...
\$ 種族  : Factor w/ 5 levels "Elf","Goblin",..: 5 4 2 1 3
\$ 儲蓄  : num  120 88 50 190 166
\$ 富有度: Ord.factor w/ 3 levels "POOR"<"OK"<"RICH": 2 1 1 3 3
``````