handle also matrix and data frame