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
• 10,430 points
46 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,040 points
0 votes

In your case it'll be,

orderedviews = arrange(movie_views, views)
view(orderedviews)
answered Nov 27, 2018 by Kalgi
• 41,990 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,690 points
571 views
0 votes
1 answer

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 darklord
• 6,170 points
158 views
0 votes
2 answers
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,040 points
407 views
0 votes
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,040 points
43 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,040 points
68 views