tksel <-
function(tukeyoutput, k=1)
{
# written by Jonathan Harrington
# the data is modifief from K. Johnson (Pitt_Shoaf2.txt)
# psh = read.table(file.path(pfad, "psh.txt"))
# carry out ANOVA
# psh.aov = aov(rt ~ Overlap * Position, data=psh)
# summary(psh.aov)
# Tukey-Test
# psh.tk = TukeyHSD(psh.aov)
# Here are the components of the Tukey-Test
# The interaction term is Overlap:Position
# and it is is position 3
# names(psh.tk)
# Select the results of the Tukey test keeping
# the first factor, Position constant
# tk.select(psh.tk[[3]])
# the same
# tk.select(psh.tk[[3]], 1)
# Select the results of the Tukey test keeping
# the second factor, Overlap constant
# tk.select(psh.tk[[3]], 2)

m = rownames(tukeyoutput)
m.un = matrix(unlist(strsplit(m, "-")), ncol=2, byrow=T)
# Number of independent variables
n = length(unlist(strsplit(m.un[1,1], ":", fixed=TRUE)))
left = matrix(unlist(strsplit(m.un[,1], ":", fixed=TRUE)), ncol=n, byrow=T)
right = matrix(unlist(strsplit(m.un[,2], ":", fixed=TRUE)), ncol=n, byrow=T)

# leave out one or more  of the columns
left = as.matrix(left[,-k])
right = as.matrix(right[,-k])
mat = NULL
for(j in 1:nrow(left)){
vec = all(left[j,]==right[j,])
mat = c(mat, vec)
}

as.matrix(tukeyoutput[mat,])
}

