How to do

We will essentially do three major things in this section. First, we calculate sector averages for fields that we can use in our relative valuation efforts. Then, we do the same at the industry level. Finally, we compare the stocks' statistics to the averages to arrive at an index value for each stock that indicates whether it might be undervalued. The following steps will guide you:

  1. In order to calculate averages in multiple columns in R, we first need to melt the data. This will make every column after Sector a row and then display its value, essentially making the data long instead of wide. Take a look at the following screenshot for the different steps in this recipe to better understand how the data changes shape. It goes ...

Get Practical Data Science Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.