inst/doc/r081attribute.r

# Run the program version for Sun et al. (2007) by source().
# Create a new object for demonstration.
# Show 3 selected observations.
source("C:/aErer/r072sunSJAF.r", echo = FALSE); getwd(); dir()
nam <- daInsNam; nam[c(3, 11, 14), ]

# Show all attributes or a specific one
attributes(x = nam)
attr(x = nam, which = "class")

# Revise or create attributes
attr(x = nam, which = "names") <- c("vari", "defi")  # Revise an old attr
attr(x = nam, which = "years") <- 2005:2008          # New numerical attr
attr(x = nam, which = "color") <- "red"              # New character attr
attr(x = daIns, which = "description") <- daInsNam   # New data.frame attr
attributes(x = nam)  # Show all attributes again
nam[c(3, 11, 14), ]  # Show 3 selected obs again

# Reveal the attribute of an object from regressions
class(ra); mode(ra); typeof(ra); length(ra); tsp(ra); names(ra)[1:4]

# Change the class for an existing object
(class(ra) <- c("glm", "lm", "myClass"))

# Methods for generic function or class
methods(generic.function = mean); methods(class = "maTrend")

Try the erer package in your browser

Any scripts or data that you put into this service are public.

erer documentation built on April 18, 2022, 5:06 p.m.