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 }
Problem: Our Armstrong number Please write code for C language So far we have worked on...
Problem: Our Armstrong number Please write code for C language So far we have worked on obtaining individual digits from 4 digits or 5 digit numbers. Then added them to find the sum of digits in various examples and assignments. However, the process of extracting individual digits is actually can be solved using a loop as you were doing a repetitive task by using mod operation and division operation. Now, we know how loops work and we can remove the...
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...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for a non-negative integer value a. The script should then evaluates the sum Pn i=1 i a using a running sum for the case when n = 5. More specifically, use a counter for i that is used in the output fprintf as well as in the running sum. Feel free to write some code and just repeat it 5 times in your script. Sample...
4. 3323 A prime number can be divided, without a remainder, only by itself and by...
4. 3323 A prime number can be divided, without a remainder, only by itself and by 1. Write a code segment to determine if a defined positive integer N is prime. Create a list of integers from 2 to N-1. Use a loop to determine the remainder of N when dividing by each integer in the list. Set the variable result to the number of instances the remainder equals zero. If there are none, set result=0 (the number is prime)....
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
Your assignment is to write a c++ function that can calculate values for any 5 th...
Your assignment is to write a c++ function that can calculate values for any 5 th order polynomial function. ?(?) = ?0 + ?1? + ?2? 2+?3? 3 + ?4? 5 + ?5? 5 Your function should accept only two parameters, the first parameter should be the value of x at which to calculate y(x). The second parameter should be an array with 6 elements that contain the coefficients a0 to a5. The output of your function should be the...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT