2015-01-23 13 views
5

Sto esaminando il libro Advanced R di Hadley. Il libro ha una domanda che mi fa davvero confuso:struttura e attributo in R

> structure(1:6, comment = "my attribute") 
[1] 1 2 3 4 5 6 

Quando si stampa l'oggetto non si vede l'attributo commento. Perché? Manca l'attributo o c'è qualcosa di speciale in questo?

Qualcuno potrebbe aiutarmi a capire cosa sta succedendo qui?

+0

È possibile accedere con 'commento()' 'Come in x <- struttura (1: 6, commentare = "attributo mio"); commento (x) 'È anche elencato in' attributes (x) ' –

risposta

8

Un attributo denominato "commento" è trattato in modo speciale dal metodo print predefinito di R. Da ?comment:

Description: 

    These functions set and query a _comment_ attribute for any R 
    objects. This is typically useful for ‘data.frame’s or model 
    fits. 

    Contrary to other ‘attributes’, the ‘comment’ is not printed (by 
    ‘print’ or ‘print.default’).