Last active
March 20, 2019 13:56
-
-
Save alstat/11ade13dac59bc2bba9d35a312038f48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(1) | |
x1 <- rnorm(10) | |
x2 <- rnorm(10) | |
out <- cbind(x1, x2) | |
colMeans(out) | |
# colMeans can be computed as follows as well | |
apply(out, 2, mean) | |
# apply - applies a mean function to column (indicated by 2) of out matrix | |
# for sd change mean to sd | |
apply(out, 2, sd) | |
# this is equivalent to | |
c(sd(out[, 1]), sd(out[, 2])) | |
# for median | |
apply(out, 2, median) | |
# this is equivalent to | |
c(median(out[, 1]), median(out[, 2])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment