Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE USE R STUDIO OR / AND UPLOAD R SCRIPT Q1(10 points): Use while loop to calculate the product of all numbers from 50 to
PLEASE USE R STUDIO OR / AND UPLOAD R SCRIPT
Q1(10 points): Use while loop to calculate the product of all numbers from 50 to 100 . Redo it using for loop. Q2 (10 points): Write a function f(x) that returns absolute value of x, that is: If x is positive, then f(x)=x If x is negative, then f(x)=x Q3 (10 points) In RStudio, please copy the following concatenate strings mydata =c ("This is me", "That my house", "Hel10, world!") Please use "regular expression" code to print out only last line (e.g. "Hello, world!")) [hint: use str_detect and $ or ] Q4 (10 points) In RStudio, please copy the follow concatenate strings Please use "regular expression" code to print out only phone numbers (e.g. last three items) [hint: use str_extract and 1 d or .] Q5 (Bonus 20 points) In time-series finance and technical analysis, moving average is a very important concept. Particularly, a n-day simple moving average ( n-day SMA) is the arithmetic average of prices of past n days at loday 1 : SMAt(n)=nPt++Ptn+1 Write a function (for instance, you can name the function as mySMA) to calculate 5 -day moving average for the past 10 days. Suppose the prices of past 10 days are 1:10 (e.g. 1,2,3,..10). The following is solution hint to help you finish: mySMAStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started