Week 4

Data structures and subsetting

Monday, Jan 27

Learning objectives

  • Attributes
  • Create data frames, matrices, arrays, and factors using attributes
  • Subset atomic and generic vectors

Materials


Subsetting and S3 objects

Wednesday, Jan 29

Learning objectives

  • Subset matrices, arrays, and data frames
  • Argument drop in subsetting
  • Subassignment
  • S3 object oriented programming system
  • Create generics and methods

Materials


Lab 4

Friday, Jan 31

GitHub

Learning objectives

  • Using git and GitHub as a team
  • Merge conflicts
  • S3 OO system

Materials


Exercise of the week

Part 1

Create date and date-time objects using function attr() or attributes(). Start with what these types of objects are built on.

Part 2

Consider the atomic vector x.

set.seed(01262020)
x <- sample(1:100, size = 100, replace = TRUE)
x
##   [1] 56 51 82 29 14 22 35 57  5 33 75  2 56 83 62  3 73 36 38 94 57 42  6
##  [24] 65 23 46 43 38  4 34 94 87 79 11 11 20 42  9 93  6 91 31 34 48 56 42
##  [47] 64 16 33 29 31 18 82 48 10 30 47 83 44 94 62 70 91 17 20 69 67 54 66
##  [70] 94 22 77 36 19 73 24 48  2 83 99 12 48 73 96 97 94 18 15 89 71 85 93
##  [93] 22 34 25 67 94  6 14 28

Use subsetting to

  1. select every third value from x beginning at position 6;

  2. remove all values with an odd index;

  3. remove every 4th value, but only if it is even;

  4. remove all numbers divisible by 3 or 5 and replace them with 0.

Previous
Next