knitr::opts_chunk$set(echo = TRUE, comment='ws#')
- The function takes an argument 'x' which needs to be a Numeric vector.
mysd <- function(x){ N <- length(x) variance <- sum((x - mean(x))^2) / (N - 1) std <- sqrt(variance) }
- Run with given input
L <- 1:20 cat(mysd(L))
- Compare with builtin sd()
cat("Built in sd():",sd(L), "\nMy function:", mysd(L))
- Alter function
mysd <- function(x){ N <- length(x) variance <- sum((x - mean(x))^2) / (N - 1) std <- sqrt(variance) list(sd = std, variance = variance) }
mysd(x = L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.