How to access the attributes of a vector in R

r

#1

I want to get the attribute of a variable in R but I am getting NULL
x<-c(T,F)

attributes(x)


#2

What attribute were you expecting to get? The class? class(x) [1] "logical" will do that. str(x) is another great way to get information about an R object. attribute(x) is for information like the dimensions, names, and class of certain objects.

Some may wonder, x has a class, so why doesn’t it have a class attribute? It does, the class attribute for vectors are hidden. You can see it appear with some objects as with data frame, matrix, array, and factor. Try attributes(factor(x)) or attributes(matrix(x))` for comparison.