EX1
讀進原始資料
dta <- read.table("student2017.txt",header=T)
對於資料在倒數第三行嘗試加入ID U76067010
newID <-"U76067010"
dta$ID <- as.character(dta$ID)
dtaNew <- data.frame(c(dta[1:13,],newID,dta[14:16,]))
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 <- "~/titanic.raw.rdata"
download.file(fL, destfile = fD)
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()
