How can I return a list of summary statistics?

Mole

I'm writing a function whose output is a list of summary statistics for a data frame of unknown columns. For example, if my data frame had 3 columns, my list output needs to be as such:

col1  
col1mean  
(mean of column 1)  

col1
col1median  
(median of column 1)

col2  
col2$mean  
(mean of column 2)

col2  
col2$median  
(median of column2)  

col3  
col3mean  
(mean of column 3)  

col3  
col3median  
(median of column 3)

My question is, how can I return my list so that it will cycle through mean, median, and standard deviation for n number of columns?

Sven Hohenstein

One approach with lapply:

# example data
set.seed(123)
dat <- data.frame(col1 = rnorm(10), col2 = rnorm(10), col3 = rnorm(10))

lapply(dat, function(x) list(mean = mean(x), median = median(x), sd = sd(x)))

The result:

$col1
$col1$mean
[1] 0.07462564

$col1$median
[1] -0.07983455

$col1$sd
[1] 0.9537841


$col2
$col2$mean
[1] 0.208622

$col2$median
[1] 0.3802926

$col2$sd
[1] 1.038073


$col3
$col3$mean
[1] -0.4245589

$col3$median
[1] -0.6769652

$col3$sd
[1] 0.9308092

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I generate email statistics from mutt header cache?

분류에서Dev

How can I return two values in a controller

분류에서Dev

how to i can return value in mvc 4

분류에서Dev

How can I obtain statistics (requests per second, response time) for an app hosted on Cloud Foundry Pivotal?

분류에서Dev

How can I create List of rectangles in TypeScript?

분류에서Dev

How can I centralize a list with css?

분류에서Dev

How can I create a resource list on Apigility?

분류에서Dev

How can I extract list from list in prolog?

분류에서Dev

How can I recreate a list of list of floats from the contents of a file?

분류에서Dev

How can I get a consistent return type from this function?

분류에서Dev

How can i return a Django ModelForm through an Jquery Ajax call?

분류에서Dev

How can I store the count of a for loop with promises that return in an arbitrary order?

분류에서Dev

How can i insert return value to mysql database in python?

분류에서Dev

How can I return a response to an AngularJS $http POST to Sinatra?

분류에서Dev

How can I write the return of a function in javascript over an image in HTML?

분류에서Dev

How can I map keys in Insert mode that contains Carriage Return in it?

분류에서Dev

How can I list the packages I removed on a specific day?

분류에서Dev

Statistics List in Tigase Component

분류에서Dev

How can I remove an entry from a list in a shells script?

분류에서Dev

How can I list last updated packages from terminal?

분류에서Dev

How can I list all applications installed in my system?

분류에서Dev

How can I use `mutate_at` for list-columns in a tibble?

분류에서Dev

How can I backup a list of mongo collections to archive using mongodump

분류에서Dev

How can I send this list as one message in discord.py?

분류에서Dev

How can I concatenate a single column of output into a list?

분류에서Dev

How can I extract list of Types from ObjectContext?

분류에서Dev

How do I get a list of programs that can be installed?

분류에서Dev

How can I check dependency list for a deb package

분류에서Dev

How can i have distinct selection from a list on the basis of id?

Related 관련 기사

  1. 1

    How can I generate email statistics from mutt header cache?

  2. 2

    How can I return two values in a controller

  3. 3

    how to i can return value in mvc 4

  4. 4

    How can I obtain statistics (requests per second, response time) for an app hosted on Cloud Foundry Pivotal?

  5. 5

    How can I create List of rectangles in TypeScript?

  6. 6

    How can I centralize a list with css?

  7. 7

    How can I create a resource list on Apigility?

  8. 8

    How can I extract list from list in prolog?

  9. 9

    How can I recreate a list of list of floats from the contents of a file?

  10. 10

    How can I get a consistent return type from this function?

  11. 11

    How can i return a Django ModelForm through an Jquery Ajax call?

  12. 12

    How can I store the count of a for loop with promises that return in an arbitrary order?

  13. 13

    How can i insert return value to mysql database in python?

  14. 14

    How can I return a response to an AngularJS $http POST to Sinatra?

  15. 15

    How can I write the return of a function in javascript over an image in HTML?

  16. 16

    How can I map keys in Insert mode that contains Carriage Return in it?

  17. 17

    How can I list the packages I removed on a specific day?

  18. 18

    Statistics List in Tigase Component

  19. 19

    How can I remove an entry from a list in a shells script?

  20. 20

    How can I list last updated packages from terminal?

  21. 21

    How can I list all applications installed in my system?

  22. 22

    How can I use `mutate_at` for list-columns in a tibble?

  23. 23

    How can I backup a list of mongo collections to archive using mongodump

  24. 24

    How can I send this list as one message in discord.py?

  25. 25

    How can I concatenate a single column of output into a list?

  26. 26

    How can I extract list of Types from ObjectContext?

  27. 27

    How do I get a list of programs that can be installed?

  28. 28

    How can I check dependency list for a deb package

  29. 29

    How can i have distinct selection from a list on the basis of id?

뜨겁다태그

보관