How to return multiple variables in R

114 Views Asked by At
min_value <- function(A){
  
  minval <- min(A[A!=0])
  index <- which(A==minval, arr.ind=TRUE)
  
  print(paste("The smallest non-zero value ", minval, " is located in:", sep=""))
  
  for(i in 1:nrow(index)){
    print(paste("row[", index[i, 1] ,"] and column[", index[i, 2], "]", sep="" ))
  }

How to print both statements out? R cannot return multiple variables :( A is a matrix btw

1

There are 1 best solutions below

0
On

You could try as a list with two elements? create an empty list inside the formula and then save the elements in the list. I guess you can return(list) at the end then and you would have both elements in "one".