Assessment of Homework 2

Overview

The following counts were obtained by inspecting the uploaded files, but without trying to run R yet.

Loading The Answers into R

I tried to load all solutions which are possibly R scripts into R.

The following list shows some of the errors which prevented files from being loaded:

Marking

Exercise ex5

As an example, here is a (randomly chosen) student solution which got 0.5 marks:

ex5 <- function(x) {
        nrow(x)
}
[source]

For marking your answer, I called the function ex5() twice, once for the full data set x and once for the first 100 rows x[1:100,]. The results were as follows:

Exercise ex6

As an example, here is a (randomly chosen) student solution which got 0.5 marks:

ex6 <- function(x) {mean(x$travel)
}
[source]

For marking your answer, I called the function ex6() twice, once for the full data set x and once for the first 100 rows x[1:100,]. The results were as follows:

Exercise ex7

As an example, here is a (randomly chosen) student solution which got 0.5 marks:

ex7 <- function(x) {mean(x$height,na.rm=TRUE)
}
[source]

For marking your answer, I called the function ex7() twice, once for the full data set x and once for the first 100 rows x[1:100,]. The results were as follows:

Exercise ex8

As an example, here is a (randomly chosen) student solution which got 0.5 marks:

ex8 <- function(x) {g <- x$gender
        sum(g=="f")
}
[source]

For marking your answer, I called the function ex8() twice, once for the full data set x and once for the first 100 rows x[1:100,]. The results were as follows:

Exercise ex9

As an example, here is a (randomly chosen) student solution which got 0.5 marks:

ex9 <- function(x) {sum(table(x$gender,x$hand)[2,2])
}
[source]

For marking your answer, I called the function ex9() twice, once for the full data set x and once for the first 100 rows x[1:100,]. The results were as follows:

Exercise ex10

As an example, here is a (randomly chosen) student solution which got 0.5 marks:

ex10 <- function(x) {(
        sum(x$gender=="m")+sum(x$hand=="l"))-(sum((x$gender=="m")&(x$hand=="l")))
}
[source]

For marking your answer, I called the function ex10() twice, once for the full data set x and once for the first 100 rows x[1:100,]. The results were as follows:

Exercise ex11

As an example, here is a (randomly chosen) student solution which got 0.5 marks:

ex11 <- function(x) {
  table(x$R)
}
[source]

For marking your answer, I called the function ex11() twice, once for the full data set x and once for the first 100 rows x[1:100,]. The results were as follows:

Exercise ex12

As an example, here is a (randomly chosen) student solution which got 0.5 marks:

ex12 <- function(x) {
table(x$gender, x$R)
}
[source]

For marking your answer, I called the function ex12() twice, once for the full data set x and once for the first 100 rows x[1:100,]. The results were as follows:

Exercise ex13

As an example, here is a (randomly chosen) student solution which got 0.5 marks:

ex13 <- function(x) {
z = sum(x$gender == "f" & x$R == "good")
y = sum(x$R == "good")
z/y
}
[source]

For marking your answer, I called the function ex13() twice, once for the full data set x and once for the first 100 rows x[1:100,]. The results were as follows:

Exercise ex14

As an example, here is a (randomly chosen) student solution which got 0.5 marks:

ex14 <- function(x) {
        maxheight <- max(x$height, na.rm=TRUE)
        x[which(x$height==maxheight),4]
}
[source]

For marking your answer, I called the function ex14() twice, once for the full data set x and once for the first 100 rows x[1:100,]. The results were as follows:

Results