R Program to find sequence,sum and mean of given numbers

How to find sequence, sum and mean

Here we are explaining how to write an R program to find the sequence, sum, and mean of the given numbers. Here we are using built-in functions seq, mean, sum for this calculation. The numbers are passed to these functions directly here. To generating regular sequences seq is a standard generic with a default method. Whereas sum returns the sum of all the values present in its arguments. The sum of the values dividing with the number of values in a data series is calculated using the mean function.

  • seq(from, to)
  • sum(…, na.rm = FALSE)
  • mean(x, trim = 0, na.rm = FALSE, …)

How sequence, sum and mean of numbers is calculated in R Program

Given below are the steps which are used in the R program to find the sequence, sum and mean of numbers. In this R program, we directly give the values to built-in functions. And print the function result.

ALGORITHM

  • STEP 1 : Use the built-in functions
  • STEP 2 : call seq() with two values from and to specifying the limit of sequence values
  • STEP 3 : call mean() with two values from and to specifying the limit of numbers
  • STEP 4 : call sum() with two values from and to specifying the limit of numbers
  • STEP 5 : print the result of each functions

R Source Code

print("Sequence of numbers from 20 to 40:")
## [1] "Sequence of numbers from 20 to 40:"
print(seq(20,40))
##  [1] 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
print("Mean of numbers from 20 to 60:")
## [1] "Mean of numbers from 20 to 60:"
print(mean(20:60))
## [1] 40
print("Sum of numbers from 51 to 91:")
## [1] "Sum of numbers from 51 to 91:"
print(sum(51:91))
## [1] 2911

R Source Code

print("Sequence of numbers from 1 to 100:")
## [1] "Sequence of numbers from 1 to 100:"
print(seq(1, 100))
##   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
##  [19]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
##  [37]  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54
##  [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72
##  [73]  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
##  [91]  91  92  93  94  95  96  97  98  99 100
print("Mean of numbers from 1 to 100:")
## [1] "Mean of numbers from 1 to 100:"
print(mean(1 : 100))
## [1] 50.5
print("Sum of numbers from 1 to 100:")
## [1] "Sum of numbers from 1 to 100:"
print(sum(1 : 100))
## [1] 5050