Cece
Cece

Reputation: 1

How to return multiple variables in R

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

Upvotes: 0

Views: 113

Answers (1)

MonicaOrt
MonicaOrt

Reputation: 56

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".

Upvotes: 1

Related Questions