Working with Data in R: difficulty 4

Mark Yourself Question

  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

A file assay.csv has two columns, group and value. It contains seven data rows:

group

value

A

12.4

A

15.0

A

13.1

B

9.8

B

11.2

B

10.5

B

-999

The instrument that produced the file writes -999 whenever a reading failed. A student runs d <- read.csv("assay.csv") and immediately computes group means.

Answer all five parts.

  1. What type does d$value have after this import, and why does the failed reading not become NA on its own?
  2. Compute the two group means the student obtains, to two decimal places each.
  3. Give the corrected read.csv call, then compute the two group means that aggregate(value ~ group, data = d, FUN = mean) returns for the corrected frame, to two decimal places each.
  4. Write the call that exports the corrected two-row summary to means.csv without adding a spurious column, and explain what the omitted argument would have produced.
  5. Name two inspection commands that would have exposed the problem before any mean was computed, and say what each would have shown.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Working with Data in R Questions: