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@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.