Question & Answer: Write a code in R-Programming Language for a function that produces the times table for its argument. The first…..

Write a code in R-Programming Language for a function that produces the times table for its argument. The first 12 values for the times table should be produced. The name of the function should be ftimes(), and when it is called with ftimes(7) the following is produced:

7 * 1 = 7

7 * 2 = 14

7 * 3 = 21

7 * 4 = 28

7 * 5 = 35

7 * 6 = 42

7 * 7 = 49

7 * 8 = 56

7 * 9 = 63

7 * 10 = 70

7 * 11 = 77

7 * 12 = 84

Expert Answer

 

#R version 3.3.2
# define a function name ftimes
ftimes <- function (num) {
#for loop in range of 12
for(i in 1:12) {
print(paste(num,’x’, i, ‘=’, num*i))
}
}

#call function
ftimes(7)

#sample output
#7 x 1 = 7
#7 x 2 = 14
#7 x 3 = 21
#7 x 4 = 28
#7 x 5 = 35
#7 x 6 = 42
#7 x 7 = 49
#7 x 8 = 56
#7 x 9 = 63
#7 x 10 = 70
#7 x 11 = 77
#7 x 12 = 84

Still stressed from student homework?
Get quality assistance from academic writers!