Q1
dta1 <- read.csv("http://titan.ccunix.ccu.edu.tw/~psycfs/dataM/Data/jdm_2016.csv",nrows = 0)
dta1 <- dta1[2:18,]
str(dta1)
## 'data.frame': 17 obs. of 6 variables:
## $ 座號 : Factor w/ 18 levels "1","10","11",..: 1 10 11 12 13 14 15 16 17 2 ...
## $ 系.年.班 : Factor w/ 9 levels " ",..: 2 3 9 6 6 6 6 5 5 5 ...
## $ 開課系序號: Factor w/ 3 levels " ","U3005","U7030": 3 3 3 2 2 2 2 2 2 2 ...
## $ 學號 : Factor w/ 18 levels "D84039018","H24001139",..: 1 2 3 6 7 8 9 12 13 14 ...
## $ 成績 : logi NA NA NA NA NA NA ...
## $ 選課時間 : Factor w/ 18 levels " ","01/18/2016 09:12:32 ",..: 18 16 11 15 2 10 7 13 3 5 ...
dta1$department <- as.character(dta1$系.年.班)%>%substring(1,3)
dta1$department <- as.factor(dta1$department)
dta1$department <- factor(dta1$department,levels(dta1$department)[c(2,4,1,3)])
barplot(with(dta1,table(department)))

Q2
dta2 <- get_citation_history('fCNw-4kAAAAJ')
plot(dta2, xlab = "Year", ylab = "Citations", type = "h",
lwd = 2, xlim = c(2008, 2018), ylim = c(0, 500),main = "Chung-Ping Cheng")

Q3
setwd("C:/Users/Cheng_wen_sung/Desktop")
jsp <- read.table("http://titan.ccunix.ccu.edu.tw/~psycfs/dataM/Data/juniorSchools.txt",header = T)
str(jsp)
## 'data.frame': 3236 obs. of 9 variables:
## $ school : Factor w/ 49 levels "S1","S10","S11",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ class : Factor w/ 4 levels "C1","C2","C3",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ sex : Factor w/ 2 levels "B","G": 2 2 2 1 1 1 1 1 1 1 ...
## $ soc : int 9 9 9 2 2 2 2 2 9 9 ...
## $ ravens : int 23 23 23 15 15 22 22 22 14 14 ...
## $ pupil : Factor w/ 1192 levels "P1","P10","P100",..: 1 1 1 413 413 512 512 512 612 612 ...
## $ english: int 72 80 39 7 17 88 89 83 12 25 ...
## $ math : int 23 24 23 14 11 36 32 39 24 26 ...
## $ year : int 0 1 2 0 1 0 1 2 0 1 ...
jsp$year <- as.factor(jsp$year)
#1
levels(jsp$year) <- c("1","2","3")
#2
colnames(jsp)[3] <- c("gender")
#3
write.csv(jsp,"jsp.csv")
Q4
dta4 <- read.table("http://www1.aucegypt.edu/faculty/hadi/RABE5/Data5/P005.txt",header = T,sep = "\t")
str(dta4)
## 'data.frame': 38 obs. of 8 variables:
## $ City : Factor w/ 38 levels "Atlanta","Austin",..: 1 2 3 4 5 6 7 9 8 10 ...
## $ COL : int 169 143 339 173 99 363 253 117 294 291 ...
## $ PD : int 414 239 43 951 255 1257 834 162 229 1886 ...
## $ URate : num 13.6 11 23.7 21 16 24.4 39.2 31.5 18.2 31.5 ...
## $ Pop : int 1790128 396891 349874 2147850 411725 3914071 1326848 162304 164145 7015251 ...
## $ Taxes : int 5128 4303 4166 5001 3965 4928 4471 4813 4839 5408 ...
## $ Income: int 2961 1711 2122 4654 1620 5634 7213 5535 7224 6113 ...
## $ RTWL : int 1 1 0 0 1 0 0 0 1 0 ...
Q5
dta5 <- read.fwf("http://www.amstat.org/publications/jse/datasets/aaup2.dat.txt",na = c(" *"," * "," *"," * "," *"),widths = c(
5,32,3,4,5,4,3,4,5,4,4,6,4,4,4,4,4
))
str(dta5)
## 'data.frame': 1161 obs. of 17 variables:
## $ V1 : int 1061 1063 1065 11462 1002 1004 1008 1009 1012 1016 ...
## $ V2 : Factor w/ 1140 levels " Abilene Christian University ",..: 6 936 937 935 5 1001 36 38 81 898 ...
## $ V3 : Factor w/ 51 levels "AK ","AL ","AR ",..: 1 1 1 1 2 2 2 2 2 2 ...
## $ V4 : Factor w/ 3 levels "I ","IIA ",..: 3 1 2 2 2 2 3 1 3 3 ...
## $ V5 : num 454 686 533 612 442 441 466 580 498 506 ...
## $ V6 : num 382 560 494 507 369 385 394 437 379 412 ...
## $ V7 : int 362 432 329 414 310 310 351 374 322 359 ...
## $ V8 : int 382 508 415 498 350 388 396 455 401 411 ...
## $ V9 : int 567 914 716 825 530 542 558 692 655 607 ...
## $ V10: int 485 753 663 681 444 473 476 527 501 508 ...
## $ V11: int 471 572 442 557 376 383 427 451 404 445 ...
## $ V12: num 487 677 559 670 423 477 478 546 523 503 ...
## $ V13: num 6 74 9 115 59 57 20 366 34 67 ...
## $ V14: num 11 125 26 124 77 33 18 354 25 40 ...
## $ V15: num 9 118 20 101 102 35 30 301 27 66 ...
## $ V16: num 4 40 9 21 24 2 0 66 3 27 ...
## $ V17: int 32 404 70 392 262 127 68 1109 89 200 ...
Q6
setwd("C:/Users/Cheng_wen_sung/Desktop")
load("./titanic.raw.rdata")
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 ...
Q7
dta7 <- read.table("http://titan.ccunix.ccu.edu.tw/~psycfs/dataM/Data/student2017.txt",header = T)
str(dta7)
## 'data.frame': 16 obs. of 1 variable:
## $ ID: Factor w/ 16 levels "C44035023","D84021057",..: 5 1 3 4 2 7 8 10 11 6 ...
fix(dta7)
dta7
## 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 U76064062
## 15 U76067010
## 16 U76041064
## 17 U76041080