November 2018
Beginner to intermediate
354 pages
6h 59m
English
Suppose the prices of three commodities, namely potatoes, rice, and oil were $10, $20, and $30 respectively in January 2018, denoted by the vector jan_price, and the prices of all these three elements increased by $1, $2, and $3 respectively in March 2018, denoted by the vector increase. Then, we can add two vectors mar_price and increase to get the new price as follows:
jan_price = c(10, 20, 30)increase = c(1, 2, 3)mar_price = jan_price + increase
To see the contents of mar_price, we just need to write it and then press Enter:
mar_price
We now see that mar_price is updated as expected:
[1] 11 22 33
Similarly, we can subtract and multiply. Remember that R uses element-wise computation, meaning that if we multiply ...
Read now
Unlock full access