Reputation: 301
In R, when I write
i=10
y=c(i:i+9)
y
I get 19 in output, whereas when I directly write
y = c(10:19)
y
Why does this happen? What does the expression mean when written in terms of i? How to do that in a loop (because I have value stored in counter variable in that case)?
Upvotes: 0
Views: 68
Reputation: 3412
Checkout:
?Syntax
:
has higher precedence than +
. It's an order of operations issue like arithmetic.
First:
10:10
Evaluates to 10
. Then:
10 + 9
Evaluates to 19
Upvotes: 5