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 in Data Analytics by chethan
24 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 21 by anonymous
• 31,840 points

Related Questions In Data Analytics

0 votes
1 answer

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

Easy Way: This Way we can easily handle ...READ MORE

answered May 7, 2018 in Data Analytics by DeepCoder786
• 1,720 points
675 views
0 votes
1 answer

How to select rows in a range from dataframe?

Hi, There are different functions to select or ...READ MORE

answered Aug 30 in Data Analytics by anonymous
• 31,840 points
18 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
1,257 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
609 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
112 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
156 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
82 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
98 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 in Data Analytics by anonymous
• 31,840 points
25 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 29 in Data Analytics by anonymous
• 31,840 points
23 views