Getting attributes of Objects in R Language - attributes() and attr() Function Last Updated : 23 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report attribute() function in R Programming Language is used to get all the attributes of data. This function is also used to set new attributes to data. Syntax: attributes(x) Parameters: x: object whose attributes to be accessed.Getting attributes of Objects in RExample 1: Implementing attributes() function R # R program to illustrate # attributes function info = data.frame(iris) # Load info set that you want to work on data(info) # Print first 6 rows of info set data head(info) # Apply attributes function attributes(info) Output: Here in the above code, we have applied the attributes() function so we have shown all the data which is present in the info data frame. So by applying info all the attributes in the datasets will be shown. Example 2: Assigning new value to the attributes in R language R # Set different column names # retain dataframe class attributes_list <- list(names = c('Sepal.Length' ,'Sepal.Width' , 'Petal.Length', 'Petal.Width', 'Species'), class = "data.frame", row.names= c("NA","NA","NA","NA")) # New attributes from list added to info database attributes(info) <- attributes_list attributes(info) Output: $names 'Sepal.Length' 'Sepal.Width' 'Petal.Length' 'Petal.Width' 'Species' $class 'data.frame' $row.names 'NA' 'NA' 'NA' 'NA' Here in the above code, we have added the new attributes to the list info from Example 1, and then printed all the attributes including the new one. attr() Function attr() will return specific data, but this function needs precise information about the data. Syntax: attr(x = data, which = "attribute_name") Parameters: x: object whose attributes to be accessed. which: string specifying the attribute to be accessed.Example: Implementing attr() function R # R program to illustrate # attr() function # Load info set that you want to work on data(info) # Apply attr() function attr(x = info, which = "names") Output: 'Sepal.Length' 'Sepal.Width' 'Petal.Length' 'Petal.Width' 'Species' Here in the above code, we have specified a particular parameter name, so only the values in names will be returned. attr() will return specific data, but attr() functions need a precise information about the data. Comment More infoAdvertise with us Next Article R - Creating, Listing, and Deleting Objects in Memory A akhilsharma870 Follow Improve Article Tags : Programming Language R Language Similar Reads Getting Multiplication of the Objects passed as Arguments in R Language - prod() Function prod() function in R Language is used to return the multiplication results of all the values present in its arguments. Syntax: prod(...) Parameters: ...: numeric or complex or logical vectors Example 1: Python3 # R program to illustrate # prod function # Initializing some vectors of element x <- 1 min read R - Creating, Listing, and Deleting Objects in Memory One of the most interesting facts about R is, what is known as objects in R are known as variables in many other programming languages. Depending on the context objects and variables can have drastically different meanings. In every computer language variables provide a means of accessing the data s 7 min read Get or Set names of Elements of an Object in R Programming - names() Function names() function in R Language is used to get or set the name of an Object. This function takes object i.e. vector, matrix or data frame as argument along with the value that is to be assigned as name to the object. The length of the value vector passed must be exactly equal to the length of the obj 2 min read Convert a Vector into Factor in R Programming - as.factor() Function as.factor() function in R Programming Language is used to convert the passed object(usually Vector) into a Factor. Syntax: as.factor(object) Parameters: Object: Vector to be convertedas.factor() Function in R ExampleExample 1: Convert a Factor in RR # Creating a vector x<-c("female", "male", "ma 1 min read Get the number of columns of an Object in R Programming - ncol() Function ncol() function in R Language is used to return the number of columns of the specified matrix. Syntax: ncol(x)Parameters: x: matrix, vector, array or data frame  Example 1:  Python3 # R program to illustrate # ncol function # Getting R Biochemical Oxygen Demand Dataset BOD # Calling ncol() functi 1 min read Convert a Numeric Object to Character in R Programming - as.character() Function as.character() function in R Language is used to convert a numeric object to character object. Syntax: as.character(x) Parameters: x: Numeric Object Example 1: Python3 1== # R program to convert a numeric object # to character object # Calling as.character() function as.character(1) as.character(2 + 1 min read Like