# [R] Use of Sappy and Tappy for Mathematical Calculation

R. Michael Weylandt <michael.weylandt@gmail.com> michael.weylandt at gmail.com
Tue Jul 10 22:00:18 CEST 2012

```
On Jul 10, 2012, at 11:30 AM, "Nordlund, Dan (DSHS/RDA)" <NordlDJ at dshs.wa.gov> wrote:

>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of Rantony
>> Sent: Tuesday, July 10, 2012 3:17 AM
>> To: r-help at r-project.org
>> Subject: [R] Use of Sappy and Tappy for Mathematical Calculation
>>
>> Hi,
>>
>> i have a matrix like this,
>>
>> ABC        XYZ    ......    .....   .....
>> -----         ------
>> 12            20      ......    .....   .....
>> 24            35      ......    .....   .....
>> 30            40      ......    .....   .....
>>
>> Here, i need to get
>>                           Sum of each columns,
>>                           Mean of each columns,
>>                           median of each columns,
>>                           mode of each columns,
>>                           Standard deviation  of each columns,
>>                           variance of each columns,
>>                           range of each columns,
>>                           count of each columns,
>>                           max of each columns,
>>                           min of each columns
>>
>> Can i get output using sappy or tappy functions ? because there have
>> alots
>> of records.

I like Dan's solution a lot and it teaches inportant idioms, but I might suggest that you use the col***() functions from the MatrixStats package if speed/data-size is of issue.

Best,
Michael

>>
>> Could you please help me fast its kind of urgent !
>>
>> - Thanks
>> Antony
>>
>
> Here is some code to get you started.  You can add in the other functions that you want.  You will need to figure out what you want to do if there are missing values.  There are built-in functions for most everything you want.  You get the range from the min and the max, and you need to decide what to do if a variable has 2 or more modes (you  will also need to determine how you are going to get the mode).
>
>
> # here is sample matrix
> mat <- matrix(1:100,nrow=10)
> colnames(mat) <- LETTERS[1:10]
>
> # define summarize function
> summarize <- function(m) {
>  sums <- apply(m, 2, sum)
>  counts <- apply(m, 2, length)
>  means <- apply(m, 2, mean)
>  return(rbind(sums, counts, means))
> }
>
> # summarize your matrix
> summarize(mat)
>
>
> Hope this is helpful,
>
> Dan
>
> Daniel J. Nordlund
> Washington State Department of Social and Health Services
> Planning, Performance, and Accountability
> Research and Data Analysis Division
> Olympia, WA 98504-5204
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

```

More information about the R-help mailing list