R:attr()和attributes()的区别

针对attr()和attributes(),现附上一段代码,帮助区别:

> x<-c(apple=2.5,orange=2.1)

> attributes(x)
$names
[1] "apple" "orange"

> attr(x,"names")
[1] "apple" "orange"
> attr(x,"names")<-c("apple","grape")
> attr(x,"type")<-"fruit"
> x
apple grape
2.5 2.1
attr(,"type")
[1] "fruit"
> attributes(x)
$names
[1] "apple" "grape"

$type
[1] "fruit"

你可能感兴趣的:(R语言)