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.

12 AN INTRODUCTION TO R[1] 1 2 3R> companies[1:3][1] "Citigroup" "General Electric"[3] "American Intl Group"In contrast <strong>to</strong> indexing with positive integers, negative indexing returns allelements that are not part of the index vec<strong>to</strong>r given in brackets. For example,all companies except those with numbers four <strong>to</strong> two-thousand, i.e., the <strong>to</strong>pthree companies, are againR> companies[-(4:2000)][1] "Citigroup" "General Electric"[3] "American Intl Group"The complete information about the <strong>to</strong>p three companies can be printed ina similar way. Because data.frames have a concept of rows and columns, weneed <strong>to</strong> separate the subsets corresponding <strong>to</strong> rows and columns by a comma.The statementR> Forbes2000[1:3, c("name", "sales", "profits", "assets")]name sales profits assets1 Citigroup 94.71 17.85 1264.032 General Electric 134.19 15.59 626.933 American Intl Group 76.66 6.46 647.66extracts the variables name, sales, profits and assets for the three largestcompanies. Alternatively, a single variable can be extracted from a data.framebyR> companies companies order_sales companies[order_sales[1:3]][1] "Cus<strong>to</strong>dia Holding" "Central European Media"[3] "Minara Resources"The indices of the three <strong>to</strong>p sellers are the elements 1998, 1999 and 2000 ofthe integer vec<strong>to</strong>r order_salesR> Forbes2000[order_sales[c(2000, 1999, 1998)],+ c("name", "sales", "profits", "assets")]© 2010 by Taylor and Francis Group, LLC

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

Saved successfully!

Ooh no, something went wrong!