between <- function(vec, dframe, sname, colname) { # for each vec in column sname of dframe, # the function returns the corresponding unique # elements from column colname mat = NULL n = names(dframe) spk = dframe[,n == sname] for(j in 1:length(vec)){ temp = spk == vec[j] o = as.character(unique(dframe[temp,n==colname])) mat$b = c(mat$b, o) mat$j = c(mat$j, j) } factor(mat$b) }