How to arrange a data set in ascending order based on a variable

0 votes
I'm sorry i'm a noob at R. I've just started learning R for work purpose. I have a dataset which consists of movie name, movie id and the views its got. So three columns - movie_id, movie_name, views. I need to arrange this data set in ascending order of the views, i.e. the movie that has got the least views on the top and the one that's got the maximum views, at the end.

How do I achieve this in R?
Nov 27, 2018 in Data Analytics by Ali
• 11,360 points
1,061 views

2 answers to this question.

0 votes

Hey @Ali, you can use the dplyr package of R for this purpose. dplyr is mainly used for data manipulation. You can try something like this:

install.packages('dplyr')
library(dplyr)
data <- read.csv("file_path.csv")
name = arrange(nameofdataframe, variable)
view(name)

where variable is the variable which will be used to arrange it in ascending order.

answered Nov 27, 2018 by Maverick
• 10,840 points
0 votes

In your case it'll be,

orderedviews = arrange(movie_views, views)
view(orderedviews)
answered Nov 27, 2018 by Kalgi
• 52,360 points

Related Questions In Data Analytics

0 votes
1 answer
0 votes
1 answer

How to create dummy variables based on a categorical variable of lists in R?

You can use mtabulate in the following way: library(qdapTools) cbind(data[1], ...READ MORE

answered Apr 13, 2018 in Data Analytics by CodingByHeart77
• 3,750 points
2,551 views
+1 vote
2 answers

How to replace a value in a data frame based on a conditional 'If' statement?

It's easier to convert alpha to characters ...READ MORE

answered Jun 6, 2018 in Data Analytics by Sahiti
• 6,370 points
36,589 views
+1 vote
3 answers

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,671 views
0 votes
1 answer

Convert java code to R code

You can rjava package for this purpose. rJava is ...READ MORE

answered Nov 16, 2018 in Data Analytics by Maverick
• 10,840 points
3,673 views
+1 vote
1 answer
0 votes
1 answer

Trying to find frequent itemsets of a data set using arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", "milk", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
749 views
0 votes
1 answer

How do I convert data frame to csv file in R?

Hey @Ali, its very simple one line ...READ MORE

answered Nov 21, 2018 in Data Analytics by Maverick
• 10,840 points
2,362 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP