Skip to content
Prev 299676 / 398503 Next

Use of Sappy and Tappy for Mathematical Calculation

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