attr(x, which, exact = FALSE) attr(x, which) <- value
whichbe matched exactly?
NULLto remove the attribute.
NULLif no exact match is found and no or more than one partial match is found.
whichamongst the attributes of
x, then (unless
exact = TRUE) a unique partial match. (Setting
options(warnPartialMatchAttr = TRUE)causes partial matches to give warnings.) The replacement function only uses exact matches. Note that some attributes (namely
tsp) are treated specially and have restrictions on the values which can be set. (Note that this is not true of
levelswhich should be set for factors via the
levelsreplacement function.) The extractor function allows (and does not match) empty and missing values of
which: the replacement function does not.
NULLobjects cannot have attributes and attempting to assign one by
attrgives an error. Both are primitive functions.
# create a 2 by 5 matrix x <- 1:10 attr(x,"dim") <- c(2, 5)
Run the code above in your browser using DataCamp Workspace