EX1

讀進原始資料

dta <- read.table("student2017.txt",header = T)

對於資料在倒數第三行嘗試加入ID U76067010

newID <-"U76067010"
# 避免加入的資料類型有差異,將ID轉為字元
dta$ID <- as.character(dta$ID)
dtaNew <- data.frame(c(dta[1:13,],newID,dta[14:16,]))
# 檔案ID整理,以免ID跑掉
names(dtaNew) <- "ID";dtaNew
##           ID
## 1  D84057058
## 2  C44035023
## 3  D84041162
## 4  D84046081
## 5  D84021057
## 6  U36037025
## 7  U36041074
## 8  U36041090
## 9  U36051087
## 10 U36031118
## 11 U36041082
## 12 U76051019
## 13 U76054025
## 14 U76067010
## 15 U76064062
## 16 U76041064
## 17 U76041080

EX2

先嘗試跟同學犯相同的錯誤

#單純以plot(women)進行
dta <- women
head(dta)
##   height weight
## 1     58    115
## 2     59    117
## 3     60    120
## 4     61    123
## 5     62    126
## 6     63    129
class(dta)
## [1] "data.frame"
plot(women)

#透過錯誤修改進行後結果無法呈現,但會出現warnings
data.entry(dta)
head(dta)
## $height
##  [1] 50 59 60 61 62 63 64 65 66 67 68 69 70 71 72
## 
## $weight
##  [1] 115 117 120 123 126 129 132 135 139 142 146 150 154 159 164
class(dta)
## [1] "list"

可以發現資料型態從原本兩個變項各15個觀察值,轉變為兩個list,也就是修改過的數值R並沒有將其視為數值上修改,而是視為字元的調整

EX3

# 下載檔案
fL <- "http://www.rdatamining.com/data/titanic.raw.rdata?attredirects=0"
fD <- "~/DM-R/titanic.raw.rdata"
download.file(fL, destfile = fD,mode = "wb")
load("C:/Users/USER/Documents/DM-R/titanic.raw.rdata")
head(titanic.raw)
##   Class  Sex   Age Survived
## 1   3rd Male Child       No
## 2   3rd Male Child       No
## 3   3rd Male Child       No
## 4   3rd Male Child       No
## 5   3rd Male Child       No
## 6   3rd Male Child       No

EX4

我只找到中平老師的帳號:P

pacman::p_load(scholar)
dta <- get_citation_history('fCNw-4kAAAAJ')
plot(dta, xlab = "Year", ylab = "Citations", type = "h", 
     lwd = 2, xlim = c(2008, 2018), ylim = c(0, 500))
grid()

## THE END