Aan de slagGa gratis aan de slag

Logical expressions and subsets

Logical expressions which use the and (&), or (|), not (!), etc. operators are a powerful tool when creating more complicated filters based on certain criteria.

In this exercise, you'll combine several 'relational operators' – equals-to (==), less than (<), greater than or equal to (>=), etc. – to write an expression that determines if the index of the maunaloa dataset falls within a certain range. You'll then take that expression and use it to extract the observations of maunaloa within that range.

Deze oefening maakt deel uit van de cursus

Manipulating Time Series Data in R

Cursus bekijken

Oefeninstructies

  • Write a logical expression for if the index of maunaloa is greater than or equal to 1990 and if the index is less than or equal to 2010; assign this to subset.

  • Use square brackets ([ and ]) to extract values from maunaloa that match the expression defined in subset and assign the result to maunaloa_subset.

  • Generate an autoplot of maunaloa_subset.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Complete the logical expression
subset <- ___ &
          ___

# Extract the subset of maunaloa
___ <- ___

# Autoplot the subsetted maunaloa dataset
___
Code bewerken en uitvoeren