Drop rows on condition from dataframe dataset

0 votes
Problem: Drop random rows on condition from dataframe/dataset.

Requirement: I want to drop rows whose sales is less then avg(sales) to rank the rest of the fields.
Aug 21, 2019 in Data Analytics by chethan
1,018 views

1 answer to this question.

0 votes
Use code as below

dataframe[which(dataframe$sales >= median(dataframe$sales)),]

or dataframe[dataframe$sales >= median(dataframe$sales),]

When you want to use condition to fetch rows from the data frame, use wither which() or provide the condition

A small trick is to change the condition to its negation and then filter when you cant use condition directly inside the data frame and add inside which().
answered Aug 22, 2019 by anonymous
• 33,030 points

Related Questions In Data Analytics

0 votes
1 answer

How to drop rows of Pandas DataFrame whose value in certain coulmns is NaN

Hi@DataKing99, You can create one function according to ...READ MORE

answered May 7, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by MD 1,704 views
0 votes
3 answers

How to select rows in a range from dataframe?

This should do it integer_location = np.where(df.index == ...READ MORE

answered Dec 16, 2020 in Data Analytics by Roshni
• 10,480 points
15,155 views
0 votes
1 answer

How to extract specific columns from a DataFrame ?

Yes there are so many ways: df[,c(V2,V4)] and another ...READ MORE

answered Apr 11, 2018 in Data Analytics by DeepCoder786
• 1,720 points
8,666 views
0 votes
1 answer

Sample random rows in DataFrame in R

First we should have some data: df1<-data.frame(matrix(rnorm(20), nrow=10)) > ...READ MORE

answered Apr 13, 2018 in Data Analytics by DeepCoder786
• 1,720 points
8,136 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,250 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,920 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by Gitika 1,182 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,339 views
0 votes
1 answer

fetch all rows with null values in dataframe or dataset - R

Use below code -  which(is.na(air)) is.na() will return a boolean ...READ MORE

answered Jul 4, 2019 in Data Analytics by anonymous
• 33,030 points
11,124 views
0 votes
1 answer

Store a built in dataset or dataframe from R to database

dbWriteTable() function allows you to store data ...READ MORE

answered Jul 30, 2019 in Data Analytics by anonymous
• 33,030 points
1,091 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