# TODO: Add comment
# 
# Author: E.Korsching  2019
###############################################################################



vectors2df <- function(x){
	# join vectors of different length to a data.frame
	# vectors might be of type character or numeric
	# inserting NA for missing values to the end of the vector
	# x: list of vectors : x=list(a,b,c, ...)
	l.len <- length(x)
	nam.x <- names(x)
	if(l.len<2){ stop("only one vector - stop") }
	l.max <- max(unlist(lapply(x, length)))
	sq <- seq(1,l.max)
	out <- x[[1]][sq]
	for(i in 2:l.len){
		out <- data.frame(out, x[[i]][sq], stringsAsFactors=F)
	}
	if(!any(nam.x=="")){ names(out) <- nam.x }else{ names(out) <- paste("a",(1:l.len),sep="") }
	return(out)
}



#a <- vectors2df(x=list(c("a","b","c"),c("a","b","c","d"),c("a","b","c","a","b","c","d")))
#a <- vectors2df(x=list(c(1,2,3),c(2,4,6,8),c(1,2,3,2,4,6,8)))
#a <- vectors2df(x=list(c("a","b","c"),c(2,4,6,8),c("a","b","c","a","b","c","d")))

#a <- vectors2df(x=list(gg=c("a","b","c"), dg=c(2,4,6,8), fg=c("a","b","c","a","b","c","d")))
#a <- vectors2df(x=list(gg=c("a","b","c"), c(2,4,6,8), fg=c("a","b","c","a","b","c","d")))



