Question

In: Computer Science

In this assignment, we will build custom functions in R. As an example, the following function...

In this assignment, we will build 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.

addPercent(.1)
[1] "10%"
addPercent(10)
[1] "1000%"
addPercent(10.1)
[1] "1010%"
addPercent(0.1443)
[1] "14.4%"

  1. 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.
  2. Write a custom R function that computes the sum of squares of two numbers.
  3. Write a custom R function that takes any univariate dataset and calculates the mean, minimum, maximum, and standard deviation.
  4. In statistics, a dataset needs to be transformed in order to meet certain assumptions. Write a custom R function that takes any univariate dataset and creates a histogram of the raw dataset and a histogram of the log-transformed dataset.
  5. Write a custom R function of your own. Describe what your function does and produce the output.

Using a Word document, include your functions along with least four different output results from each of the functions 1 through 5. Provide screenshots of the output results in a Word document that shows the current date.

Solutions

Expert Solution

#R version 3.4.4
#THE FOLLOWING ARE THE FUNCTIONS YOU NEEDED I GAVE ONE EXAMPLE PER FUNCTION , THE ADDED PIC SHOWS THE WORKING OUTPUT
convert_fahr_to_celsius <- function(temp) {
celsi <- ((temp - 32) * (5 / 9)) #givenformula
return(celsi)
}
sum_of_square <- function(x,y)
    {
    sum = ((x*x) + (y*y))
    return (sum)
    }
too_many_func <- function(x)
{
result.mean <- mean(x)
print(result.mean)
result.min <- min(x)
print(result.min)
result.max <- max(x)
print(result.max)
sd(x)#GIVES THE STANDARD DEVIATION
}
draw_hist <- function(x)
{
hist(x)
}
add_two_num <- function(x,y)
{
total = (x+y)
return(total)
}
print(convert_fahr_to_celsius(100))#calling the function to convert fahrenheit to celsius
print(sum_of_square(2,3))#calling the function to compute the sum of squares of two numbers
x <- c(12,7,3,4.2,18,2,54,-21,8,-5)#univariate dataset
too_many_func(x)#calling the function to find mean, minimum, maximum and standard deviation
draw_hist(x)#calling the function to draw histogram
add_two_num(5,7)#calling the function to add two numbers my own function



Related Solutions

Assignment Write each of the following functions. The function header must be implemented exactly as specified....
Assignment Write each of the following functions. The function header must be implemented exactly as specified. Write a main function that tests each of your functions. Specifics In the main function ask for a filename and fill a list with the values from the file. Each file should have one numeric value per line. This has been done numerous times in class. You can create the data file using a text editor or the example given in class – do...
GAGE R & R EXERCISE in this example, we do a gage R&R study on two...
GAGE R & R EXERCISE in this example, we do a gage R&R study on two data sets: one in which measurement system variation contributes little to the overall observed variation (GAGEAIAG.MTW), and one in which measurement system variation contributes a lot to the overall observed variation (GAGE2.MTW). For comparison, we analyze the data using both the ANOVA and the Xbar and R method. The GAGEAIAG data was taken from Measurement Systems Analysis Reference Manual, 3rd edition. (Chrysler, Ford, General...
In this question, we are going to call a function, f : R → R, type...
In this question, we are going to call a function, f : R → R, type A, if ∀x ∈ R, ∃y ∈ R such that y ≥ x and |f(y)| ≥ 1. We also say that a function, g, is type B if ∃x ∈ R such that ∀y ∈ R, if y ≥ x, then |f(y)| ≥ 1. Prove or find a counterexample for the following statements. (a) If a function is type A, then it is type...
Suppose that for ABC Company we have the following functions:     Inverse Demand Function:   P =...
Suppose that for ABC Company we have the following functions:     Inverse Demand Function:   P = 360 - 0.8Q     Cost Function: 120 + 200Q     Marginal Revenue Function (MR) = 360 – 1.6Q     Marginal Cost (MC) = 200 Determine quantity (Q) and price (P) that maximizes profit for ABC Company. Show your calculations.
1. What do we mean by a "production function"? Interpret the following production functions. (a) Q...
1. What do we mean by a "production function"? Interpret the following production functions. (a) Q = 50L^3/4 K^1/4 (b) Q = 640K L^2-K^2L^3
Requirements: In this assignment, you are going to create two switch functions. The first function is...
Requirements: In this assignment, you are going to create two switch functions. The first function is going to be called switchVal and the second is going to be called switchRef. The goal of this assignment is to demonstrate the understanding of what pass-by-reference (Links to an external site.) and pass-by-value (Links to an external site.) do when working with functions that you create. The two functions that you will modify need to accept two parameters and inside them they need...
C++ program assignment asks to implement the following functions. Each function deals with null terminated C-strings....
C++ program assignment asks to implement the following functions. Each function deals with null terminated C-strings. Assume that any char array passed into the functions will contain valid, null-terminated data. The functions must have the signatures listed below. 1. This function returns the last index where the target char can be found in the string. it returns -1 if the target char does not appear in the string. For example, if s is “Giants” and target is ‘a’ the function...
Woodworking Inc. is a private company. The custom build furniture.
Woodworking Inc. is a private company. The custom build furniture. On June 1, 2021 Jill Wong signs a contract for Woodworking Inc. to build her a custom dining room set. She has to pay 15% on signed of the contract and will pay the balance on deliver on August 1, 2021. The selling price was $10,000 and the cost to build the furniture was $2,800.   Prepare the journal entries for June 1st and August 1st. 
You are supposed to build a custom ALU that can perform the following operations: Multiplication Addition...
You are supposed to build a custom ALU that can perform the following operations: Multiplication Addition Division Logical OR Select all necessary components below, to create this ALU. Multiplexer Demultiplexer OR gate AND gate NOT gate Encoder Priority Encoder Decoder Adder Subtractor Multiplier Divider Shifter Register Register File
We can build a heap by repeatedly calling the insert function to insert the elements into...
We can build a heap by repeatedly calling the insert function to insert the elements into the heap. Here is pseudocode: buildHeap(A) h = new empty heap   for each element e in A       h.insert(e)             What is the Big-O runtime of this version of buildHeap? Justify your answer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT