12.07.2015 Views

R dummies

R dummies

R dummies

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Just as before, you can sort the data frame some.states in decreasing order ofpopulation. Try it, but this time don’t assign the order to a temporary variable:> some.states[order(some.states$Population, decreasing=TRUE), ]Region Population IncomeCalifornia West 21198 5114Florida South 8277 4815Georgia South 4931 4091....Arkansas South 2110 3378Delaware South 579 4809Alaska West 365 6315Sorting on more than one columnYou probably think that sorting is very straightforward, and you’re correct.Sorting on more than one column is almost as easy.You can pass more than one vector as an argument to the order() function.If you do so, the result will be the equivalent of adding a secondary sortingkey. In other words, the order will be determined by the first vector and anyties will then sort according to the second vector.Next, you get to sort some.states on more than one column — in this case,Region and Population. If this sounds confusing, don’t worry — it really isn’t. Try ityourself. First, calculate the order to sort some.states in the order of region as wellat population:> index some.states[index, ]Region Population IncomeConnecticut Northeast 3100 5348Delaware South 579 4809Arkansas South 2110 3378Alabama South 3615 3624Georgia South 4931 4091Florida South 8277 4815Alaska West 365 6315Arizona West 2212 4530Colorado West 2541 4884California West 21198 5114

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

Saved successfully!

Ooh no, something went wrong!