Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 204
Warning – Partialmatching
ОглавлениеWhile the function attr()
allows partial matching. It is never a good idea to use partial matching in a batch environment. This can lead to hard to detect programming errors.
Some slots – like class
, comment
, dim
, dimnames
, names
, row.names
and tsp
(for time series objects) – are special: they can only take some values. This knowledge can even be used to change those attributes.
x <- 1:9 x # x is a vector ## [1] 1 2 3 4 5 6 7 8 9 class(x) ## [1] “integer” attr(x, “dim”) <- c(3,3) x # is is now a matrix! ## [,1] [,2] [,3] ## [1,] 1 4 7 ## [2,] 2 5 8 ## [3,] 3 6 9 class(x) # but R is not fooled. ## [1] “matrix”