Search code examples
rvectorattributesatomic

How to access the atomic vector attributes?


I have set the attributes for a variable using the attr function as below :

x <- 1 :20
attr(x,'name') <- c("RED","BLUE")
attributes(x)

$name
[1] "RED"  "BLUE"

Now that I have set the attributes; if I access it using '$' it says "Error : $ operator is invalid for atomic vectors". I also tried x['name'] which shows NA

How do I access this atomic vector attributes?


Solution

  • If I understand your question,

     attr(x, 'name')
    #[1] "RED"  "BLUE"
    

    Or

     attributes(x)$name
    #[1] "RED"  "BLUE"