cis-ds / Discussion

Public discussion
10 stars 15 forks source link

Confused about Arithmetic Operators #141

Closed kathleencannell closed 4 years ago

kathleencannell commented 4 years ago

In Section 5.5.1 of the textbook it says arithmetic operators "are all vectorised, using the so called “recycling rules”. If one parameter is shorter than the other, it will be automatically extended to be the same length. This is most useful when one of the arguments is a single number."

I am confused about what it means to be vectorized and what it means to automatically extend a parameter to be the same length. Can someone provide clarity on this?

bensoltoff commented 4 years ago

We will cover this in more detail next week. Essentially all columns in a data frame are each a vector. Vectors contain individual values. You can perform arithmetic on numeric vectors (columns). If you tried to add vectors of different lengths together. The shorter one repeats to match the length of the longer one. So if you had a column and you wanted to add 1 to all of the values, you could just write column_name + 1 rather than writing our 1 a bunch of times

kathleencannell commented 4 years ago

Oh okay that makes sense, thank you!