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.
Getting attributes of Objects in R Language – attributes() and attr() Function
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.
Contact Us