Dear R users,
I would like to construct a matrix of seasonal dummy variables, such matrix can 
be written as follows(i.e format(T,4))
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
1    0   0   0
0    1   0   0
0    0   1   0
0    0   0   1
.    .     .    .
.    .     .     .
  etc
I have written the following small 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
+} 
+}
+} 
I have obtained the following message from R consol:
> T=100
> br<-matrix(0,T,4)
> 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 : syntax error, unexpected '}' dans "{+ br[i,j]=1"
> 
>        + if else (abs(i-j)%%4==0)
Erreur : syntax error, unexpected ELSE, expecting '(' dans "       + if else"
>             {+ br[i,j]=1
+             +}
Erreur : syntax error, unexpected '}' dans "            {+ br[i,j]=1"
>        + else 
Erreur : syntax error, unexpected ELSE dans "       + else"
>             {+ br[i,j]=0
+             +} 
Erreur : syntax error, unexpected '}' dans "            {+ br[i,j]=0"
> +}
Erreur : syntax error, unexpected '}' dans "+}"
> +} 
Erreur : syntax error, unexpected '}' dans "+}"
> 
I would require if you can rectify my program in order to obtain this matrix of 
seasonal dummies. Many thanks in advance.
        [[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to