R Array Operations
Hi All,
See the Array operations
> a = c(1, 2, 5, 4)
> b = c(1,1, 4, 8)
See the Array operations
> a = c(1, 2, 5, 4)
> b = c(1,1, 4, 8)
Then, if we multiply a by 5, we would get a vector with each of its elements multiplied by 5.
> 5 * a
[1] 5 10 25 20
[1] 5 10 25 20
The same can be done with other arithmetic operators.
> a + b
> a - b
> a * b
> a / b
> a * b
> a / b
Recycling Rule
If two arrrays are of unequal length, the shorter one will be recycled in order to
match the longer vector.
> w = c(10, 20, 30)
> v = c(1, 2, 3, 4, 5, 6, 7, 8, 10)
> w + v
[1] 11 22 33 14 25 36 17 28 40
> v = c(1, 2, 3, 4, 5, 6, 7, 8, 10)
> w + v
[1] 11 22 33 14 25 36 17 28 40
Comments
Post a Comment