9 Arguments
9.1 Arguments
9.2 Mandatory argument
- Arguments that must be supplied with appropriate values while calling the function.
9.3 Default argument value
- Arguments with default value will be considered if no value is given while calling the function.
9.4 Argument matching
Matched by argument names
Matched by argument positions
Matched by a mix of argument names and positions
Partial matching is possible
-
Order of argument matching
- Check for the exact match
- Check for the partial match
- Check for the positional match
9.5 Conduct a t.test
The R function
t.test
peforms one and two sample t-tests on vectors of data.Conduct a t-test to compare if the mean mpg is different between automatic and manual transmission.
Code
set.seed(1234)
n = 20
y1 = round(rnorm(n, 16, 4), 2)
g1 = rep("1", length = n)
y2 = round(rnorm(n, 20, 4), 2)
g2 = rep("2", length = n)
DF = data.frame(y = c(y1, y2), Group = c(g1, g2), stringsAsFactors = TRUE)
t.test(y ~ Group, data = DF, alternative = "two.sided", mu = 0, paired = FALSE, var.equal = FALSE,
conf.level = 0.95)
t.test(y ~ Group, alternative = "two.sided", paired = FALSE, data = DF, var.equal = FALSE,
conf.level = 0.95, mu = 0)
t.test(y ~ Group, alt = "two.sided", mu = 0, pa = FALSE, var = FALSE, conf = 0.95,
dat = DF)
9.6 The ...
argument
- A way to provide further arguments to or from other functions
Code
`?`(cat)
`?`(rep)
`?`(seq)
`?`(paste)
- Advantage of
...
arguments- to extend the functionality of another function
- when the number of arguments passed to the function cannot be known in advance
- arguments comming after the
...
must be named explicitly and cannot be partially matched or matched positionally
9.7 Example: cat
Using cat
to concatenate text
9.8 Function call
Python does not perform partial matching of function arguments like R does. You need to provide the exact argument name when calling a function.