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,300 points
271 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,290 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,720 points
1,144 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,360 points
23,447 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,640 points
19,914 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
1,373 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
133 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
1,072 views