這份作業希望能夠讓你熟習於 R 的基本 data structure,打好地基之後蓋房子才穩,題目包含 variable assignment, vector, list, dataframe 等。其中幾題提供 expected output 讓你對答案,祝你寫作業愉快!
滿分共 100 分。
請創建 3 個變數,var_credits
代表你本學期的學分數,var_perhour
代表你預計平均每學分的每周投入課業的時間,var_study
用前面兩個變數相乘,代表你本學期每周預計投入課業的總時間,最後請將var_study
印出。
助教不會根據投入時間評斷你,請放心填答,謝謝。
### your code
下方提供 Readr 所開放的臺灣 COVID-19 確診病例資料,並已經抓出前十位確診者的性別、年齡、狀態。請分別印出這十位患者中
<- read.csv("data/AS01/covid19_comfirmed_case_taiwan.csv")
df <- df$gender[1:10]
vector_gender <- df$age[1:10]
vector_age <- df$state[1:10]
vector_state
### your code
# (1)
# (2)
# (3)
# output should be
#> [1] "male"
#> [1] "Above 50"
#> [1] "released" "isolated" "released" "released" "released"
同上方資料
vector_gender_first3_last3
為名,利用[]
,創造出一個包含前 3 位患者與末 3 位患者性別的 vector。df_first10
為名,將 vector_gender
, vector_age
, vector_state
拼成一個 dataframe,並將結果印出。### your code
# (1)
# (2)
下方列出部分新聞所本學期開設課程,包含教師姓氏, 課程名稱, 修課限制人數, 開設單位等。請協助
student_quota
元素,將修課限制人數加倍,並將 list_journalism_sample$student_quota
印出,造成老師困擾weekday
,內容為 c("三","二","五","三")
,並將list_journalism_sample$weekday
印出<-
list_journalism_sample list(teacher=c("chen","hung","liu","lee"),
course=c("新聞寫作","數位新聞法規與倫理","採訪寫作二"," 新聞編輯與資訊設計"),
student_quota=c(20,15,9,20),
dept="journalism")
### your code
# (1)
# (2)
# (3)
# (4)
# output should be
#> [1] "chen" "hung" "liu" "lee"
#> [1] 16
#> [1] 40 30 18 40
#> [1] "三" "二" "五" "三"
在回到臺灣 COVID-19 確診病例資料。
df_first20
的 dataframe,裡面僅有前 20 位確診者df_first20
中女性(female)的年齡(age)df_first20
中編號(patient_id)為奇數者的確診日期(released_date)df_first20
中五十歲以上(Above 50)者女性的的狀態(state)df_first20
中,五十歲以上者以外所有人的旅遊史(tourism_history)<- read.csv("data/AS01/covid19_comfirmed_case_taiwan.csv")
df ### your code
# (1)
# (2)
# (3)
# (4)
# (5)
# output should be
#> [1] "Above 50" "Above 50" "Above 50" "Above 50" "Above 70" "Above 70"
#> [7] "Above 40" "Above 20" "Above 50" "Above 40"
#> [1] "2020-02-06" "" "2020-02-19" "2020-02-29" "2020-02-29"
#> [6] "2020-02-27" "2020-02-26" "" "2020-02-27" ""
#> [1] "released" "isolated" "released" "released" "isolated"
#> [1] "Yes" "Yes" "No" "Yes" "Yes" "Yes" "Yes" "Yes" "Yes" "No"