The R Project SVN R

Rev

Rev 61150 | Rev 66721 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61150 Rev 61168
Line 86... Line 86...
86
## Sort the columns of a matrix
86
## Sort the columns of a matrix
87
apply(x, 2, sort)
87
apply(x, 2, sort)
88
 
88
 
89
##- function with extra args:
89
##- function with extra args:
90
cave <- function(x, c1, c2) c(mean(x[c1]), mean(x[c2]))
90
cave <- function(x, c1, c2) c(mean(x[c1]), mean(x[c2]))
91
apply(x,1, cave,  c1 = "x1", c2 = c("x1","x2"))
91
apply(x, 1, cave,  c1 = "x1", c2 = c("x1","x2"))
92
 
92
 
93
ma <- matrix(c(1:4, 1, 6:8), nrow = 2)
93
ma <- matrix(c(1:4, 1, 6:8), nrow = 2)
94
ma
94
ma
95
apply(ma, 1, table)  #--> a list of length 2
95
apply(ma, 1, table)  #--> a list of length 2
96
apply(ma, 1, stats::quantile)# 5 x n matrix with rownames
96
apply(ma, 1, stats::quantile) # 5 x n matrix with rownames
97
 
97
 
98
stopifnot(dim(ma) == dim(apply(ma, 1:2, sum)))
98
stopifnot(dim(ma) == dim(apply(ma, 1:2, sum)))
99
 
99
 
100
## Example with different lengths for each call
100
## Example with different lengths for each call
101
z <- array(1:24, dim = 2:4)
101
z <- array(1:24, dim = 2:4)