Exercise

Data Utilities

R features a bunch of functions to juggle around with data structures::

  • seq(): Generate sequences, by specifying the from, to, and by arguments.
  • rep(): Replicate elements of vectors and lists.
  • sort(): Sort a vector in ascending order. Works on numerics, but also on character strings and logicals.
  • rev(): Reverse the elements in a data structures for which reversal is defined.
  • str(): Display the structure of any R object.
  • append(): Merge vectors or lists.
  • is.*(): Check for the class of an R object.
  • as.*(): Convert an R object from one class to another.
  • unlist(): Flatten (possibly embedded) lists to produce a vector.

Remember the social media profile views data? Your LinkedIn and Facebook view counts for the last seven days have been pre-defined as lists.

Instructions

100 XP
  • Convert both linkedin and facebook lists to a vector, and store them as li_vec and fb_vec respectively.
  • Next, append fb_vec to the li_vec (Facebook data comes last). Save the result as social_vec.
  • Finally, sort social_vec from high to low. Print the resulting vector.