Please change 林木木 to your name, and 411073221 to your school id.

The exam has two part:

Part 1: Multiple choices (full mark = 72)

12 Questions. Each is worth 6 points. Please run the following command to visit the form for multiple choices.

browseURL("https://docs.google.com/forms/d/e/1FAIpQLSflXzhzA9ft-bVJNMgshQb-fl5M9_p0RGDo9BCLX2ZaBFWmIA/viewform?usp=sf_link")

Part 2: Programming Question (Full mark is 30)

One big question with 5 small questions. Each is worth 6 points.

Before you start

Each question is framed like:

Create an object named practice and bind a numeric value of 5 to it.

# practice

The Question

1 Econ Survey

An online survey is distributed to students of Economics department.

1.1 Storing questions

There are two questions:

Suppose the following retrieval will print each question respectively:

survey$questions[[1]] # will show as
"Are you happy with our campus? Choose a number from 5(very happy), 4(happy), 3(satisfy), 2( unhappy), to 1(very unhappy)."
survey$options[[1]] # will show as
c(1, 2, 3, 4, 5)

survey$questions[[2]] # will show as
"Did you participate in any of the following activities? Check all that apply to you. (student association, school club, school sport team, department sport team)"
survey$options[[2]] # will show as
c("student association", "school club", "school sport team", "department sport team")

Construct the survey object that can satisfy the above retrieval outcomes:

# declare then add method
survey <- list() # declare
survey$questions[[1]] <- "Are you happy with our campus? Choose a number from 5(very happy), 4(happy), 3(satisfy), 2( unhappy), to 1(very unhappy)." # then-add
survey$options[[1]] <- c(1, 2, 3, 4, 5)

survey$questions[[2]] <- "Did you participate in any of the following activities? Check all that apply to you. (student association, school club, school sport team, department sport team)"
survey$options[[2]] <- c("student association", "school club", "school sport team", "department sport team")

# survey

1.2 One observation

One student's response is

Construct an object named single_response whose structure satisfies the following requirements:

choice1 <- single_response$questions[[1]]
survey$options[[1]][[choice1]] # will show as
4

choice2 <- single_response$questions[[2]]
survey$options[[2]][choice2] # will show as 
c("school club", "department sport team")
single_response <- list() # declare
single_response$questions[[1]] <- 4
single_response$questions[[2]] <- c(2, 4)

# single_response

1.3 Several observations

There are three students responded to the survey. Their choices are

Store three responses in responses object so that for i=1

i=1
survey$options[[1]][
  responses[[i]]$questions[[1]]
] # show student i's chosen option from question 1 as
4
survey$options[[2]][
  responses[[i]]$questions[[2]]
] # show student i's chosen options from question 2 as
c("school club", "department sport team")
responses <- list(
  list(
    questions=list(
      c(4), c(2, 4) 
    )
  ),
  list(
    questions=list(
      c(3), c(NA)
    )
  ),
  list(
    questions=list(
      c(5), c(1, 2, 3)
    )
  )
)

# responses

1.4 Modify

Modify responses so that:

# version 2
responses[[1]]$questions[[1]] <- 3
responses[[3]]$questions[[1]] <- 3
responses[[2]] <- NULL

# responses

1.5 Feature by feature

responses from the previous question is an observation-by-observation data set. We want to construct a feature-by-feature data set. The feature names are:

For question2.XXX features, their values are logical. TRUE means the student has participated in activity XXX; FALSE means has not. Please construct a feature-by-feature list data set for those three students based on their 1.3 answers, and save the data set to object responses_fbf

responses_fbf <-
  list(
    question1 = c(4, 3, 5), 
    question2.student_association = c(F, NA, T), 
    question2.school_club = c(T, NA, T), 
    question2.school_sport_team = c(F, NA, T),
    question2.department_sport_team = c(T, NA, F)
  )

# responses_fbf


tpemartin/rmdgrader documentation built on Nov. 22, 2022, 6:39 p.m.