knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

powers

The goal of the powers package is to perform basic computations on numerical vectors.

This package has four exported functions: square(), cube(), box_cox() and my_log(). There is one internal function pow() which these four functions depend on.

These four functions only work for numerical input. When the input is of other type, an "invalid input" message will be returned.

Description & Examples

In this section I will explain the arguments of each function and give some examples for each function.

First, load my powers package.

library(powers)

(1) The function square(x,na.omit) squares a vector.

num_vec <- c(0, -4.6, 3.4, NA)
square(num_vec)

square(num_vec, na.omit=TRUE)

num_vec2 <- c(0, -4.6, 3.4, "a")
square(num_vec2)

(2) The functioncube(x,na.omit) raises a vector to the power of 3.

num_vec <- c(0, -4.6, 3.4, NA)
cube(num_vec)

cube(num_vec, na.omit=TRUE)

num_vec2 <- c(0, -4.6, 3.4, "a")
cube(num_vec2)

(3) The functionbox_cox(y, lambda1, lambda2, na.omit) calculate the box cox transform of a vector. Here is the formula of the transformation: cox box (formula source: wikipedia)

num_vec <- c(0, -4.6, 3.4, NA)
box_cox(num_vec,4,6) # not omit NA

box_cox(num_vec,4,6,na.omit=TRUE) # omit NA

box_cox(num_vec,4,2,na.omit=TRUE) # lambda2 too small

box_cox(num_vec,6,2,na.omit=TRUE) # lambda1 >5

num_vec2 <- c(0, -4.6, 3.4, "a")
box_cox(num_vec2,4,6)

(4) The functionmy_log(x,base=exp(1),na.omit=FALSE) perform log transformation.

my_log(exp(7))
num_vec <- c(0, 8,64,NA)
my_log(num_vec,2) # not omit NA

my_log(num_vec,2, na.omit = TRUE) # omit NA

num_vec1 <- c(0, 4.6, 900000000000000000)
my_log(num_vec1,1.5) # can not calculate x > base^100

my_log(-10,2) # x can not be negative

num_vec2 <- c(0, -4.6, 3.4, "a")
my_log(num_vec2,4)


hannahdxz/powers documentation built on May 29, 2019, 12:04 p.m.