11.07.2015 Views

Preface to First Edition - lib

Preface to First Edition - lib

Preface to First Edition - lib

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8 AN INTRODUCTION TO RA vec<strong>to</strong>r is the elementary structure for data handling in R and is a set ofsimple elements, all being objects of the same class. For example, a simplevec<strong>to</strong>r of the numbers one <strong>to</strong> three can be constructed by one of the followingcommandsR> 1:3[1] 1 2 3R> c(1,2,3)[1] 1 2 3R> seq(from = 1, <strong>to</strong> = 3, by = 1)[1] 1 2 3The unique names of all 2000 companies are s<strong>to</strong>red in a character vec<strong>to</strong>rR> class(Forbes2000[,"name"])[1] "character"R> length(Forbes2000[,"name"])[1] 2000and the first element of this vec<strong>to</strong>r isR> Forbes2000[,"name"][1][1] "Citigroup"Because the companies are ranked, Citigroup is the world’s largest companyaccording <strong>to</strong> the Forbes 2000 list. Further details on vec<strong>to</strong>rs and subsettingare given in Section 1.6.Nominal measurements are represented by fac<strong>to</strong>r variables in R, such as thecategory of the company’s business segmentR> class(Forbes2000[,"category"])[1] "fac<strong>to</strong>r"Objects of class fac<strong>to</strong>r and character basically differ in the way their valuesare s<strong>to</strong>red internally. Each element of a vec<strong>to</strong>r of class character is s<strong>to</strong>red as acharacter variable whereas an integer variable indicating the level of a fac<strong>to</strong>ris saved for fac<strong>to</strong>r objects. In our case, there areR> nlevels(Forbes2000[,"category"])[1] 27different levels, i.e., business categories, which can be extracted byR> levels(Forbes2000[,"category"])[1] "Aerospace & defense"[2] "Banking"[3] "Business services & supplies"...© 2010 by Taylor and Francis Group, LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!