简体   繁体   English

如何在循环中创建向量

[英]How to create vectors in a loop

In R, when I write在 R 中,当我写

i=10
y=c(i:i+9)
y

I get 19 in output, whereas when I directly write我在输出中得到 19,而当我直接写

y = c(10:19)
y

Why does this happen?为什么会发生这种情况? What does the expression mean when written in terms of i?当用 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 .评估为10 Then:然后:

10 + 9 

Evaluates to 19评估为19

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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