full conditions! [🇷 for BE/BA]
Dear Helmut,
the code is worth a thousand sentences
the code is worth a thousand sentences
loc.stat <- function(x, type, na.rm, distr) {
non.numerics <- which(is.na(suppressWarnings(as.numeric(x))))
x[non.numerics] <- NA
x <- as.numeric(x)
if (distr == "nonpar") {
switch (type,
pct2.5 = as.numeric(quantile(x, probs=0.025, na.rm=na.rm)),
pct25 = as.numeric(quantile(x, probs=0.25, na.rm=na.rm)),
median = as.numeric(median(x, na.rm=na.rm)),
pct75 = as.numeric(quantile(x, probs=0.75, na.rm=na.rm)),
pct97.5 = as.numeric(quantile(x, probs=0.975, na.rm=na.rm)))
} else if (distr == "normal") {
mean.x <-mean(x, na.rm=na.rm)
sd.x <- sd(x, na.rm=na.rm)
n.not.nas <- length(x)-length(which(is.na(x)))
se <- sd.x/sqrt(n.not.nas)
switch (type,
cla2.5 = mean.x+qt(0.025, df=n.not.nas-1, lower.tail=TRUE)*se,
ar.mean = mean.x,
cla97.5 = mean.x+qt(0.975, df=n.not.nas-1, lower.tail=TRUE)*se)
} else {
NULL
}
}
set.seed(123456)
x <- rnorm(12, 100, 20)
median <- loc.stat(x, "median", TRUE, "nonpar")
mean <- loc.stat(x, "ar.mean", TRUE, "normal")
—
Kind regards,
Mittyri
Kind regards,
Mittyri
Complete thread:
- R Inferno Helmut 2019-04-26 16:03 [🇷 for BE/BA]
- full conditions!mittyri 2019-04-26 16:20
- full conditions! Helmut 2019-04-26 16:41
- full conditions! d_labes 2019-04-27 14:29
- magik of R implicit return mittyri 2019-04-27 22:23
- magik of R implicit return ElMaestro 2019-04-27 22:34
- implicit return? d_labes 2019-04-28 19:36
- implicit return? ElMaestro 2019-04-28 20:36
- implicit return? Helmut 2019-04-28 20:50
- implicit return? ElMaestro 2019-04-28 21:16
- implicit return? Helmut 2019-04-28 23:38
- implicit return? ElMaestro 2019-04-29 09:40
- implicit return? Helmut 2019-04-29 10:41
- implicit return? ElMaestro 2019-04-29 12:55
- built-in ifelse mittyri 2019-04-30 13:05
- implicit return? ElMaestro 2019-04-29 12:55
- implicit return? Helmut 2019-04-29 10:41
- implicit return? ElMaestro 2019-04-29 09:40
- implicit return? Helmut 2019-04-28 23:38
- implicit return? ElMaestro 2019-04-28 21:16
- implicit return? d_labes 2019-04-28 19:36
- magik of R implicit return ElMaestro 2019-04-27 22:34
- magik of R implicit return mittyri 2019-04-27 22:23
- full conditions!mittyri 2019-04-26 16:20