8:27
help.search
(which does the same as ??
)
RSiteSearch
%/%
all.equal(x, pi)
or, even better, isTRUE(all.equal(x, pi))
At least two of the following:
<-
assign
Inf
and -Inf
0
, Inf
, and -Inf
numeric
, integer
, and complex
nlevels
as.numeric("6.283185")
summary
, head
, str
, unclass
, attributes
, or View
. Bonus points if you’ve discovered tail
, the counterpart to head
that prints the last few rows.
rm(list = ls())
seq.int(0, 1, 0.25)
name = value
pairs when the vector is created, or by calling the names
function afterward.
3 * 4 * 5 = 60
%*%
3
. The inner list counts as one element, and so does the NULL
element.
formals
, or in the global environment variable .Options
.
$
) operator.
Thirdly, you can call the subset
function.
check.names = FALSE
to data.frame
.
rbind
for appending vertically or cbind
for appending horizontally.
list2env
is the best solution, but as.environment
also works.
formals
, args
, and formalArgs
.
do.call
calls a function with its arguments in a list form.
format
, formatC
, sprintf
, and prettyNum
are the main ones.
alarm
, or printing an \a
character to the console.
factor
and ordered
NA
).
cut
to bin it.
if
will throw an error if you pass NA
to it.
ifelse
will return NA
values in the corresponding positions where NA
is passed to it.
switch
will conditionally execute code based upon a character or integer argument.
break
into your loop code.
next
into your loop code.
lapply
, vapply
, sapply
, apply
, mapply
, and tapply
were all discussed in the chapter, with eapply
and rapply
getting brief mentions too. Try apropos("apply")
to see all of them.
lapply
always returns a list, vapply
always returns a vector or array as specified by a template, and sapply
can return either.
rapply
is recursive, and ideal for deeply nested objects like trees.
tapply
(or something from the plyr
package).
**ply
, the first asterisk denotes the type of the first input argument and the second asterisk denotes the type of the return value.
library
throws an error if it fails, whereas require
returns a logical value (letting you do custom error handling).
.libPaths
returns a list of libraries.
POSIXct
classes must be used. Dates don’t store the time information, and POSIXlt
dates store their data as lists, which won’t fit inside a data frame.
"%B %Y"
x<-
Sys.time()
x+
3600
## [1] "2013-07-17 22:44:55 BST"
60 * 60 * 24 * 365
seconds. A period of one year will be 366 days in a leap year.
data
function with no arguments.
read.csv
assumes that a decimal place is represented by a full stop (period) and that each item is separated by a comma, whereas read.csv2
assumes that a decimal place is represented by a comma and that each item is separated by a semicolon. read.csv
is used for data created in locales where a period is used as a decimal place (most English-speaking locales, for example). read.csv2
is for data created in locales where a comma is used (most European locales, for example). If you are unsure, simply open your data file in a text editor.
read.xlsx2
from the xlsx
package is a good first choice, but there is also read.xlsx
in the same package, and different functions in several other packages.
read.csv
, or use download.file
to get a local copy.
readLines
, call str_count
to count the number of instances in each line, and sum
the total.
with
, within
, transform
, and mutate
all allow manipulating columns and adding columns to data frames, as well as standard assignment.
order
or arrange
.
TRUE
when you have a positive number—for example, is.positive <- function(x) x > 0
—and call Find(is.positive, x)
.
min
returns the single smallest value of all its inputs. pmin
accepts several vectors that are the same length, and returns the smallest at each point along them.
pch
(“plot character”) argument.
y ~ x
.
set.seed
), generate the numbers, then reset the seed to the same value.
d
, followed by the name of the distribution. For example, the PDF for the binomial distribution is dbinom
. CDF functions start with p
followed by the name of the distribution, and inverse CDF functions begin with q
followed by the name of the distribution.
anova
, AIC
, and BIC
are common functions for comparing models.
summary(model)$r.squared
.
warnings
function shows the previous warnings.
try
returns an object of class try-error
.
testthat
equivalent of checkException
is expect_exception
. Say that 10 times fast.
quote
turns a string into a call, then eval
evaluates it.
print.foo
will be called for objects of class foo
.
roxygenise
or roxygenize
.Deprecated
. Later, replace the body completely with a call to .Defunct
.