# [R] rectify a program of seasonal dummies matrix

jim holtman jholtman at gmail.com
Wed Aug 22 04:26:43 CEST 2007

if i==j

should be

if (i == j)

same with your use of 'if else'.  You need to use the correct syntax.
you are using the incorrect syntax.

On 8/21/07, hassen62 at voila.fr <hassen62 at voila.fr> wrote:
> Hi friends,
> I would like to construct a matrix of seasonal dummies with number of rows (observations)=100. such matrix is written as follows:[1 0 0 0;0 1 0 0;0 0 1 0;0 0 0 1;1 0 0 0;0 1 0 0;0 0 1 0;0 0 0 1;etc...] . I wrote the following program:
> T=100
> br=matrix(0,T,4)
> {
> for (i in 1:T)
> for (j in 1:4)
> if i==j
> br[i,j]=1
> if else (abs(i-j)%%4==0
> br[i,j]=1
> else
> br[i,j]=0
> }
> z<-br
> z
>
> but unfortunately I obtained from the console the following message:
> > {
> + for (i in 1:T)
> +      for (j in 1:4)
> +         (if i==j)
> Erreur : syntax error, unexpected SYMBOL, expecting '(' dans :
> "
> "
> >             br[i,j]=1
> Erreur dans br[i, j] = 1 : objet "i" non trouvé
> >
> >         (if else (abs(i-j)%%4==0)
> Erreur : syntax error, unexpected ELSE, expecting '(' dans "        (if else"
> >             br[i,j]=1
> Erreur dans br[i, j] = 1 : objet "i" non trouvé
> >         else
> Erreur : syntax error, unexpected ELSE dans "        else"
> >             br[i,j]=0
> Erreur dans br[i, j] = 0 : objet "i" non trouvé
> >               }
> Erreur : syntax error, unexpected '}' dans "              }"
> >
> Can you please rectify my smal program, I tried to rectify it but I can't. Many thanks in advance.
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>
>

--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?