> x <- sample(1:10) > x [1] 7 6 2 1 10 4 9 8 5 3 > x <- runif(10) > x [1] 0.675563246 0.793751488 0.522873648 0.464818236 0.000796533 0.570979090 [7] 0.207529500 0.964427924 0.784340894 0.896253832 > order(x) [1] 5 7 4 3 6 1 9 2 10 8 > x[order(x)] [1] 0.000796533 0.207529500 0.464818236 0.522873648 0.570979090 0.675563246 [7] 0.784340894 0.793751488 0.896253832 0.964427924 > order(x) [1] 5 7 4 3 6 1 9 2 10 8 > rank(x) [1] 6 8 4 3 1 5 2 10 7 9 x(runif(20), 4, 5) > x [,1] [,2] [,3] [,4] [,5] [1,] 0.73557265 0.3947122 0.5651739 0.24265531 0.2735317 [2,] 0.50665113 0.5554681 0.4629307 0.56533170 0.8605197 [3,] 0.02711503 0.4104189 0.2410183 0.09087188 0.1283659 [4,] 0.54371873 0.9006658 0.4643194 0.15817379 0.2985341 > fred <- order(x[ , 1]) > fred [1] 3 2 4 1 > x[fred, ] [,1] [,2] [,3] [,4] [,5] [1,] 0.02711503 0.4104189 0.2410183 0.09087188 0.1283659 [2,] 0.50665113 0.5554681 0.4629307 0.56533170 0.8605197 [3,] 0.54371873 0.9006658 0.4643194 0.15817379 0.2985341 [4,] 0.73557265 0.3947122 0.5651739 0.24265531 0.2735317 > logit <- function(x) log(x / (1 - x)) > > logit <- function(x) { + if (! all(0 < x & x < 1)) + stop("x out of range") + return(log(x) - log(1 - x)) + } > logit function(x) { if (! all(0 < x & x < 1)) stop("x out of range") return(log(x) - log(1 - x)) } > logit(runif(6)) [1] -0.0725970 -1.0398455 -1.2060969 -1.0482238 0.6123538 -2.3970485 > logit(rnorm(6)) Error in logit(rnorm(6)) : x out of range nvlogit <- function(y) return(1 / (1 + exp(-y))) > invlogit function(y) return(1 / (1 + exp(-y))) > invlogit(-1e5) [1] 0 > invlogit(1e5) [1] 1 > invlogit(rnorm(10)) [1] 0.16643767 0.45642178 0.40880002 0.90832263 0.62639185 0.59987019 [7] 0.43509410 0.15410533 0.32867641 0.08052868 > invlogit <- function(y) 1 / (1 + exp(-y)) > invlogit(rnorm(10)) [1] 0.4077599 0.8937644 0.6488439 0.3724861 0.6210030 0.6088171 0.5773330 [8] 0.3089661 0.5055685 0.6996838 > "fred" <- function(x, y) x + 2 * y > "%fred%" <- function(x, y) x + 2 * y > > x <- 1:5 > y <- x * 10 > x %fred% y [1] 21 42 63 84 105 > x %fred% c(y, 100) [1] 21 42 63 84 105 201 Warning message: longer object length is not a multiple of shorter object length in: x + 2 * y