I am trying to get the top ‘n’ companies from a data frame.Here is my code below.
data("Forbes2000", package = "HSAUR")
sort(Forbes2000$profits,decreasing=TRUE)
Now I would like to get the top 50 observations from this sorted vector.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
headandtailare really useful functions!If you want the first 50 rows of the data.frame, then you can use the
arrangefunction fromplyrto sort thedata.frameand then useheadNotice that I wrapped
profitsin a call todescwhich means it will sort in decreasing order.To work without plyr