arithSeq: arithSeq

Description Usage Arguments Value Author(s) Examples

View source: R/pscript1.R

Description

Takes in the common difference (d), the first term (a1), and the number of terms wanted (n) and stores the first n terms of that sequence in a vector

Usage

1
arithSeq(d,a1,n)

Arguments

d

common difference of the sequence

a1

first term of the series

n

number of terms to be stored in the vector

Value

Returns a numeric vector containing the first n terms of the sequence

Author(s)

Matt Heffernan, University of Illinois at Chicago

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
arithSeq(1,0,5)
Returns a vector containg a sequence of 5 terms with a common difference of 1 and an inital term of 0
(0 1 2 3 4)
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
arithSeq <- function(d,a1,n)
{
  count <- 0
  sequence <- vector()
  while(count < n)
  {
    sequence <- append(sequence, (a1 + (count)*d))
    count <- count+1
  }

  return(sequence)

}

mheffe3/MyFirstPackage documentation built on Dec. 21, 2021, 5:52 p.m.