Created
January 22, 2015 09:33
-
-
Save jaehyeon-kim/ee2e82d03b0ff6b87028 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyData <- data.frame(Year=seq(2000,2009)) | |
# year variables | |
dim <- length(MyData$Year) | |
yMat <- matrix(NA, nrow=dim, ncol=dim) | |
for(i in 1:dim) { | |
yMat[i,] <- rbind(t(MyData)) # transpose | |
} | |
yMat | |
# dummy variables | |
dMat <- matrix(0, nrow=dim, ncol=dim) | |
for(j in 1:dim) { | |
for(i in 1:dim) { | |
if(i > j) | |
dMat[i,j]=1 | |
} | |
} | |
dMat | |
# linear variables | |
lMat <- matrix(0, nrow=dim, ncol=dim) | |
for(j in 1:dim) { | |
for(i in 1:dim) { | |
if(i > j) | |
lMat[i,j]=lMat[i-1,j]+1 | |
} | |
} | |
lMat | |
# quadratic/cube variables | |
qMat <- lMat^2 | |
qMat | |
cMat <- lMat^3 | |
cMat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment