Quantcast
Channel: Add element in a vector while looping in R - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Add element in a vector while looping in R

$
0
0

I have a problem to solve in R language but I may need to add element in a loop while I am looping into it with a for, but the loop does not go through the new values.

I made a simple loop to explain the type of problem I have.

Here is the code:

c=c(1,2)for(i in c){    c=c(c,i+2)    print(i)}

And the result:

[1] 1[1] 2

I would like this result:

[1] 1[1] 2[1] 3[1] 4

It continues until I reach a condition.

Can someone tell me wether it is possible or not with an other way?

Thank you,

Robin


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images