R does not support multiple return values. You want to do something like:
foo = function(x,y){return(x+y,xy)} plus,minus = foo(10,4)
Yes? Well, you canβt. You receive an error message that R cannot return multiple values.
You have already found a solution - put them in a list, and then get data frames from the list. This is effective - there is no conversion or copying of data frames from one memory block to another.
This is also logical, the return from the function should conceptually be a single object with some value that is passed to any function that calls it. This value is also better conveyed if you name the return values ββof a list.
You can use the technique to create multiple objects in a calling environment, but when you do this, kittens die.
Note in your example, carYear not a data frame β its character vector of column names.
source share