title: Function returning a dataset in R
body: <p>I have written the below function in R to split a data set into Test/Train. I need my code to create 2 datasets called test and train. I am getting the result, however, it is being printed to the console. I need it to be created as a dataset.</p>
  
  <pre><code>    splt &lt;- function(x,y){
      intrain &lt;- sort(sample(nrow(x), nrow(x)*y))
      train &lt;- x[intrain,]
      test &lt;- x[-intrain,]
      train &lt;- data.frame(train)
      test &lt;- data.frame(test)
      return(test)
      return(train)
      }
      splt(iris,0.75)
  </code></pre>
  
  <p>I am using the inbuilt 'iris' dataset in R. The aim of the code is to sample 75% of the dataset randomly and store it as 'train' and store the remaining as 'test'. I need the function to create 2 data frames by itself and not just display them in the console. Also, I do not want to explicitly assign it to a variable outside the function to create a dataframe like <code>train &lt;- splt(iris,0.75)</code>. I want the function to create data frames by itself. Is there any way to do it..? Is it even possible..? </p>
  
  <p>Your help is much appreciated.</p>