dimanche 19 avril 2020

For loop to extract data

I Have data set with these variables (Branch, Item, Sales, Stock) I need to make a for loop to extract a data with the following

The same item which has
1-different branches
2- its sales is higher than the stock

and save the result in data frame The code I used is


trials <- sample_n(Data_with_stock,1000)

for (i in  1:nrow(trials)) 
{
if(trials$sales[i] >  trials$stock[i] & trials$item[i] =  trials$item[i] & trials$branch[i] !=  trials$branch[i+1])

{s <-data.frame( (trials$NAME[i])
  ,(trials$branch[i]))
} 

}

Aucun commentaire:

Enregistrer un commentaire