21

Can a function in R return not one, but two vectors?

(I am really beginning with R, so I might be overlooking something simple)

jogo
  • 12,469
  • 11
  • 37
  • 42
Karel Bílek
  • 36,467
  • 31
  • 94
  • 149
  • 5
    See this relevant question: http://stackoverflow.com/questions/1826519/function-returning-more-than-one-value – gd047 Feb 23 '10 at 13:25
  • As @george-dontas points out, this question/answer should be tagged as duplicate. – emagar Sep 03 '21 at 08:05
  • Does this answer your question? [Returning multiple objects in an R function](https://stackoverflow.com/questions/8936099/returning-multiple-objects-in-an-r-function) – emagar Sep 03 '21 at 08:07

1 Answers1

25

Return them in a list:

return(list(v1 = v1, v2 = v2))
zx8754
  • 52,746
  • 12
  • 114
  • 209
teucer
  • 6,060
  • 2
  • 26
  • 36