how to use Xn list (X(1), X(2), X(3) variables in an equation and get the result automatically for all variables as a loop

good morning you'll,

I have a quick question and would really appreciate your help and suggestions
i am trying to use X(n) of numbers in an equation and result in Y(n) of the result for example:

I have X(1), X(2), X(3) variables as input
X(1) = 1
X(2) =3
X(3) =2
C =2
the equation is [ Y(n)= X(n)+C]

Y(1)= X(1)+C
Y(1)= 1+2
Y(1) = 3

Y(2)= 5
Y(3)= 4

I want to get the result of Y(1), Y(2), Y(3) all together
how can I use a loop to import X(1) value and get Y(1) value result and import X(2) value and get Y(2) value and so on.

thanks in advance

Best Regards
Ahmed Ali
PhD candidate in Architecture
Chung Ang University

Many functions in R are vectorized so you do not have to use explicit loops. For example, in the code below the constant C is added to each element of the vector X.

X <- c(1, 3, 2)
X
#> [1] 1 3 2
C <- 2
Y <- X + C
Y
#> [1] 3 5 4

Created on 2019-10-09 by the reprex package (v0.2.1)

2 Likes

thanks alot FJCC for the quick reply
this is what I was looking for