Question

APPLIED STATISTICS 2 USE R CODE ! SHOW R CODE! Write a function to calculate the...

APPLIED STATISTICS 2

USE R CODE ! SHOW R CODE!

Write a function to calculate the sum of cubes from 1 to n, but skip the multiple of 5. Say, if n=10, the result is 1^3+2^3+3^3+4^3+6^3+7^3+8^3+9^3. The input is the value of n, the output is the summation. (you need if statement to check whether a number is a multiple of 5.In R, a%%b is the remainder for a divided by b. So, we have 10%%5=0)

APPLIED STATISTICS 2

USE R CODE ! SHOW R CODE!

Homework Answers

Answer #1

#Function name =Cube_excl_mult_5

Cube_excl_mult_5 = function(n){
   x=1:n # vector of number from 1to n
   y=which(x%%5!=0) #Identifying position where we do not have multiple of 5
   x_new=x[y] # considering only those where we do not have multiple of 5
   #Output
   return(sum(x_new^3))

}

____________________________________

##E.g
> Cube_excl_mult_5(4)
[1] 100
> Cube_excl_mult_5(5)
[1] 100

____________________________________________________________
If you have any doubt please let me know through comment
Please give positive vote if you find this solution helpful. Thank you!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use R Studio (show the code and output) Please write an R function named “outlier_detect” to...
Use R Studio (show the code and output) Please write an R function named “outlier_detect” to return or print out the outliers from a given data vector. outlier_detect = function(x){ #x: a column of numeric vector Body of code }
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop (instead of for). • The function takes a single integer n as a parameter • The function prints a series between 1 and that parameter, and also prints its result • The result is calculated by summing the numbers between 1 and n (inclusive). If a number is divisible by 5, its square gets added to the result instead. • The function does not...
In R- Studio : Write a function that takes as an input a positive integer and...
In R- Studio : Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Write a recursive function, do not use any of the loop commands in your code.
USE C++ Write a sum() function that is used to find the sum of the array...
USE C++ Write a sum() function that is used to find the sum of the array through pointers. In this program we make use of * operator. The * (asterisk) operator denotes the value of variable. Input: array = 2, 4, -6, 5, 8, -1 Output: sum = 12
Show that the series \sum_{n=1}^{\infty} 1/(x^2 + n^2) defines a differentiable function f: R -> R...
Show that the series \sum_{n=1}^{\infty} 1/(x^2 + n^2) defines a differentiable function f: R -> R for which f' is continuous. I'm thinking about using Cauchy Criterion to solve it, but I got stuck at trying to find the N such that the sequence of the partial sum from m+1 to n is bounded by epsilon
Question (2) [5 marks] (Use R) Suppose you have a company producing cupcakes. Each cupcake is...
Question (2) [5 marks] (Use R) Suppose you have a company producing cupcakes. Each cupcake is supposed to contain 10 grams of sugar. The cupcakes are produced by a machine that adds the sugar in a bowl before mixing everything. You believe the machine does not add 10 grams of sugar for each cupcake. If your assumption is true, the machine needs to be fixed. You stored the level of sugar of thirty cupcakes. Note: You can create a randomized...
Use R to code a function to generate a random sample of size n from the...
Use R to code a function to generate a random sample of size n from the Beta(a, b) distribution by the acceptance-rejection method. (1) Generate a random sample of size 3000 from the Beta(4,3) distribution. (2) Graph the histogram of the sample with the theoretical Beta(4,3) density superimposed. Answer the above questions by showing the R codes and results.
1. Code is already written please show all outputs and comment on function of code. 2....
1. Code is already written please show all outputs and comment on function of code. 2. These are Python 3 programs. Please show outpouts and comment on fuctions. Note: this is a bit of a “backwards” exercise – we show you code, you figure out what it does. As a result, not much to submit – don’t worry about it – you’ll have a chance to use these in other exercises. >>> feast = ['lambs', 'sloths', 'orangutans', 'breakfast cereals', 'fruit...
write a code in python Write the following functions below based on their comments. Note Pass...
write a code in python Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries. #!/usr/bin/python3 #(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are...
using matlab please present code for the following (ALL PARTS PLEASE AND THANK YOU) 1. No...
using matlab please present code for the following (ALL PARTS PLEASE AND THANK YOU) 1. No Input/No Output Write a function that has no input and no outputs. This function will simply display some text when it is called. (this is my code, are there suggestions for improvements?) function Display() disp('some text') end 2. 1 Input/No Outputs Write a function with one input and no outputs. This function will simply display a variable that is provided as an input argument....