Use of Sappy and Tappy for Mathematical Calculation
-----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.
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