Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205399

change name in variables R whit for

$
0
0

I'm trying to create variables to use, for each variable it's called, M000 M001 M002 M003

Example

c.n_vars <- nrow(comb)
for (i in 1:c.n_vars)
{
paste("M",comb[i,1],comb[i,2],comb[i,3]) = Arima(y,order=c(arima[1,1],arima[2,1],arima[3,1]),seasonal=list(order=c(comb[i,1],comb[i,2],comb[i,3]),period=12))
}

where comb is all combinations

a <- c(0,1,2,3,4)
b <- c(0,1,2,3,4)
c <- c(0,1,2,3,4)
comb <- expand.grid(a, b,c)



row parameter1 parameter2 parameter3
1     0           0          0
2     1           0          0
3     2           0          0
4     3           0          0
5     4           0          0
6     0           1          0
7     1           1          0
8     2           1          0
9     3           1          0
10    4           1          0
11    0           2          0
12    1           2          0
13    2           2          0
14    3           2          0
15    4           2          0

and arima is

arima <- data.frame(c(2,1,4))

row parameters
1       2
2       1
3       4

i am trying to create

c.n_vars <- nrow(comb)
for (i in 1:c.n_vars)
{
paste("M",comb[i,1],comb[i,2],comb[i,3]) = Arima(y,order=c(arima[1,1],arima[2,1],arima[3,1]),seasonal=list(order=c(comb[i,1],comb[i,2],comb[i,3]),period=12))
}

this code must return

    for i = 1

    M000 = arima model saved in that variable

    for i = 2

    M100 = arima model saved in that variable

    for i = 3

    M200 = arima model saved in that variable
.
.
.
.
.
for i = 15

  M420 = arima model saved in that variable

and the following error appears

Error in paste("M", comb[i, 1], comb[i, 2], comb[i, 3]) = Arima(y, order = c(arima[1,  :  
     assignment target expands an object out of language

I need that each iteration of the variable 'i' be saved in a different variable

Is there any solution? or another way to do it


Viewing all articles
Browse latest Browse all 205399

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>