Exercises-01

fL <- "student2017.txt"
dta <- read.table(fL, h = T)
dta$ID <- as.character(dta$ID)
miss <- "U76067010"
dta2 <- data.frame(c(dta[1:13, ], miss, dta[14:16, ]))
names(dta2) <- "ID";dta2 
##           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

Exercises-02

dta <- women
class(dta)
## [1] "data.frame"
head(dta)
##   height weight
## 1     58    115
## 2     59    117
## 3     60    120
## 4     61    123
## 5     62    126
## 6     63    129
data.entry(dta)
class(dta)
## [1] "list"
head(dta)
## $height
##  [1] 58 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

data.entry()會使資料類別從“data.frame”轉為“list”,所以無法畫圖。

Exercises-03

fL <- "http://www.rdatamining.com/data/titanic.raw.rdata?attredirects=0"
fD <- "~/data/titanic.raw.rdata"
download.file(fL, destfile = fD, mode = "wb")
load("C:/Users/USER/Documents/data/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
str(titanic.raw)
## 'data.frame':    2201 obs. of  4 variables:
##  $ Class   : Factor w/ 4 levels "1st","2nd","3rd",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ Sex     : Factor w/ 2 levels "Female","Male": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Age     : Factor w/ 2 levels "Adult","Child": 2 2 2 2 2 2 2 2 2 2 ...
##  $ Survived: Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...

Exercises-04

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