Uh!

[This article was first published on Stats raving mad » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Didn’t know this…

a<-structure(c(25,34,12,5),.Names=c("0","2","4","7+"))
> data
 0  2  4 7+
25 34 12  5

It’s becoming clear that I have learned R in the most unstructured way…I always do it in two stages :ashamed:

> data<-c(25,34,12,5)
> names(data)<-c("0","2","4","7+")
> data
 0  2  4 7+
25 34 12  5

It’s really useful to wrap it all in a single function.

Attribute Specification

Description:

 ‘structure’ returns the given object with further attributes
 set.

Usage:

 structure(.Data, ...)

Arguments:

 .Data: an object which will have various attributes attached to it.

 ...: attributes, specified in ‘tag=value’ form, which will be
 attached to data.

Details:

 Adding a class ‘"factor"’ will ensure that numeric codes are
 given integer storage mode.

 For historical reasons (these names are used when deparsing),
 attributes ‘".Dim"’, ‘".Dimnames"’, ‘".Names"’,
 ‘".Tsp"’ and ‘".Label"’ are renamed to ‘"dim"’,
 ‘"dimnames"’, ‘"names"’, ‘"tsp"’ and ‘"levels"’.

 It is possible to give the same tag more than once, in which case
 the last value assigned wins.  As with other ways of assigning
 attributes, using ‘tag=NULL’ removes attribute ‘tag’ from
 ‘.Data’ if it is present.

Share/Bookmark

To leave a comment for the author, please follow the link and comment on their blog: Stats raving mad » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)