Custom Function in R CT6 MIS476
Custom functions in R. As an example, the following function called addPercent converts a value into a percentage with one decimal place.
addPercent <- function(x){
percent <- round(x*100, digits = 1)
result <- paste(percent, “%”, sep = “”)
return(result)
}
Below are a few output results from this function.
> add Percent(.1)
[1] “10%”
> add Percent(10)
[1] “1000%”
> add Percent(10.1)
[1] “1010%”
> add Percent(0.1443)
[1] “14.4%”
- Write a custom R function that inputs a temperature in Fahrenheit Fo and converts to Celsius Co. The relationship is Co = 5(Fo – 32)/9.
- Write a custom R function that computes the sum of squares of two numbers.
- Write a custom R function that takes any univariate data set and calculates the mean, minimum, maximum, and standard deviation.
- In statistics, a data set needs to be transformed in order to meet certain assumptions.
- Write a custom R function that takes any univariate data set and creates a histogram of the raw data set and a histogram of the log-transformed data set.
- Write a custom R function of your own. Describe what your function does and produce the output.