If your only concern is that your function returns a matrix then regardless of what your preceding data types/structures are you could always just finalize the output as a matrix unless you need the preceding data processing to work with a matrix structure, which doesn't sound the like problem at all.
see fundamental example below:
x <- c(1:5)
y <- c(6:10)
foo <- function(x, y){
z <- cbind(x,y)
return(as.matrix(z))
}
z <-foo(x,y)
z