It depends on what is in a and b . If they are just numbers, try returning the vector as follows:
dim <- function(x,y) return(c(x,y)) dim(1,2)[1] # [1] 1 dim(1,2)[2] # [1] 2
If a and b are something else, you might want to return a list
dim <- function(x,y) return(list(item1=x:y,item2=(2*x):(2*y))) dim(1,2)[[1]] [1] 1 2 dim(1,2)[[2]] [1] 2 3 4
EDIT:
try the following: x <- c(1,2); names(x) <- c("a","b") x <- c(1,2); names(x) <- c("a","b")
source share