You can add any general attribute to an object with attr you can also use attr to look up the value of any attribute of an object. The only time R will complain is when a function needs to find an attribute and it is not there. It will let you add any attributes that you like to an object (and then it will usually ignore them). R is very laissez faire when it comes to attributes. Or to give an object a new attribute altogether: levels(deck) <- c( "level 1", "level 2", "level 3") Or to change an attribute’s value: row.names(deck) <- 101 : 152 You can use any of these functions to retrieve an attribute’s value: row.names(deck) However, R also has row.names, levels, and many other attribute-based helper functions. You’ve already met the names, dim, and class functions, which each work with an eponymously named attribute. R comes with many helper functions that let you set and access the most common attributes used in R. If you run attribute on the deck data frame that you created in Project 2: Playing Cards, you will see: attributes(deck) You can see an object’s attributes with attribute. Data frames also store their class, "ame", as an attribute. For example, a data frame stores its row and column names as attributes. Attributes do not affect the values of the object, but stick to the object as a type of metadata that R can use to handle the object. In Attributes, you learned that many R objects come with attributes, pieces of extra information that are given a name and appended to the object.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |