1

I'm attempting to write my first wrap function, showing the mean, variance, stdev, and summary for a vector in r

des_function = function(y)
  {
  mean(y); 
  var(y);
  sd(y);
  summary(y);
  }
des_function(even)

but it's only showing the results of the summary function:

des_function(even)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    2.0   251.5   501.0   501.0   750.5  1000.0

Thanks!

2 Answers2

1

I would suggest this slight change:

#Function
des_function = function(y)
{
  list(
  mean(y), 
  var(y),
  sd(y),
  summary(y)
  )
}
#Apply
des_function(even)
Duck
  • 39,058
  • 13
  • 42
  • 84
0

We could create a tibble and return the tibble

library(tibble)
des_function <- function(y) {
        tibble(Mean = mean(y), Var = var(y), SD = sd(y), Summary = list(summary(y)))
 }
akrun
  • 874,273
  • 37
  • 540
  • 662