简体   繁体   中英

How to create vectors in a loop

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)?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM