Selecting top 10 and bottom 10 based in R: Easy approach

In my previous article you would have seen how to rank the data in a table. In this blog we will see how simple it is in R to display the Top 10 records. I assume that you have the dataset ready with ranking done. Before we even looking at ranking we will find out we can select specific column from the data table:

Selecting specific columns from the data table:

> RankedScores[,c(‘Name’,’TotalScores’,’Rank’)]



We have selected only the required fields such as Name, TotalScores and Rank. In this you can realize that all the 20 records are shown even thought its ordered by rank. Now we will see how we can select Top 10 from the same set of data.

> RankedScores[1:10,c(‘Name’,’TotalScores’,’Rank’)]

To display the bottom 10 data

> RankedScores[20:10,c(‘Name’,’TotalScores’,’Rank’)]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s