R uses functions to perform operations. To run a function called funcname
, we type funcname(input1, input2)
,
where the inputs (or arguments) input1
and input2
tell R how to run the function. A function can have any number
of inputs. For example, to create a vector of numbers, we use the function
c()
(for concatenate). Any numbers inside the parentheses are joined together.
The following command instructs R to join together the numbers
1, 3, 2, and 5, and to save them as a vector named x.
When we type x, it gives us back the vector.
> x <- c(1, 3, 2, 5)
> x
[1] 1 3 2 5
Note that the > is not part of the command; rather, it is printed by R to indicate that it is ready for another command to be entered. We can also save things using = rather than <-:
> x = c(1, 6, 2)
> x
[1] 1 6 2
> y = c(1, 4, 3)
c()
function to store the values 5, 6, 1 and 2 in a variable named x
.Replace the
...
with your code