okay we covered matrix arithmetic which
means the time has come to talk about
some more data science oriented
operations cool I'm almost certain that
if you have our studio open as you're
going through the lessons you will a
grasp everything a lot better but that's
a given and B have the matrix dot map
data we created in the previous lesson
loaded if you have started a new session
and don't have the script from last time
saved I have entered the code we used as
comments so feel free to recreate the
matrix because that's what we'll be
using in this lesson
all right so I have my matrix of US and
worldwide box-office crossings for the
Matrix movie franchise and I want to
learn how much in total all three movies
made at the box office both around the
world
and in the US only
luckily there is the simplest command in
our that lets me do that it's called
cold sums and it returns the sum for
each column in your data structure the
only argument you need to pass is your
data like this
there these are the sums of all values
in each of the two columns
notice that the S for sums is
capitalized remember that our is
case-sensitive language if you don't use
the proper capitalization x' or won't
know what you want it to do right as you
can probably guess if there is a called
sums there will probably also be a row
sums function just as it was with the
call names and borough names and our
bind and c bind and there is let's try
it out even though it isn't too useful
in our particular situation because one
of our columns contains the worldwide
box office figures and the other
contains the US cross which is part of
the worldwide statistic nonetheless
now we have the total u.s. and worldwide
grosses for each movie in the trilogy
fantastic what if I wanted to know how
much on average the movies made in the
US and across the globe well I can use
the coal means function it works exactly
like columns but gives us the means for
the columns in our data structure like
this again be mindful of the capital M
because R is case-sensitive awesome
we can also do raw means and that will
give us the averages for each row in the
matrix
and there it is
we can now find out the sums and the
means for columns in ravenna matrix that
is super super useful when working with
larger data and you want to get a quick
feel for what it has in store for you
often it will be useful to save the sums
and averages you compute a separate rows
and columns and add them to your data
structure
can you guess one way to do that I'll
give you a couple of seconds of course
you can save each output as a vector and
then simply bind what you need displayed
in the matrix with our bind and see bind
let's try it out
I will go back up and see if the columns
and coal means results in two vectors
called total and average
and I will create a new matrix called
matrix dot prelim with our bind and
stick the two new vectors to the bottom
of my data
and there you have it a nice and neat
little matrix that tells a number in
front story excellent
okay let's wrap it up here but before we
go I have one final question the blue
pill or the red pill you take the blue
pill the story ends you wake up in your
bed and believe whatever you want to
believe you take the red pill you stay
in our land and I will show you how deep
the rabbit-hole goes for more videos
like this one please subscribe