Assume we have following table where we have each two pairs of variables to be tested with each other (the original table has far more columns):http://pastebin.com/igeMTaSB
How can I create a loop in R so that it applies a function each one or two rows in a script?
Example Code:
library(urca)
library(lmtest)
# Load data (See link)
table = read.csv("test.csv", header = TRUE, sep=",")
table = data.frame(table)
table
# For each column in the table (a1-d2), do
VARselect(table$column,lag.max = 10,type="both")
# For each two sequent pairs in the table (a1+a2, b1+b2,c1+c2,d1+d2), do
grangertest(table$a1, table$a2, order = 1, na.action = na.omit)
sapplyorlapply:lapply(table, function(i) VARselect(i,lag.max = 10,type="both")).