0

What my data usually looks like when the AS 400 produced schedules

 df <- data.frame(
   Date = c(rep("Dec 4", 10)),
   Line = c(rep(1,7),rep(2,3)),
   Style = c(rep(24510,7),rep(18605,3)),
   Qty = c(1,1,3,1,2,1,1,2,1,3))  

This is what I want my data to look like. If you notice, the rows with style number 24510, have no been compressed to one row, with a quantity of 10. Before there were 7 individual rows with different quantities.

 df_goal <- data.frame(
   Date_goal = c(rep("Dec 4", 2)),
   Line_goal = c(1,2), 
   Style_goal = c(24510,18605),
   Qty_goal = c(10,6))  
M--
  • 25,431
  • 8
  • 61
  • 93

2 Answers2

1

Pretty easy with dplyr

library(dplyr)

df_goal<-df %>% 
            group_by(Date,Line, Style ) %>% 
            summarize(Qty=sum(Qty)) %>%
            rename(Date_Goal =Date, Line_Goal=Line, Style_Goal=Style, Qty_Goal= Qty)
CER
  • 854
  • 10
  • 22
  • no worries, somehow `Qty` was converted to `factor`. Anyhow, this is a dupe of an [tag:r-faq] so, not very important how the question/data is presented. It has just rewording value. – M-- Dec 10 '18 at 16:31
0

If you just want a total-count, this one is the simplest:

plyr::count(df, vars=c('Date', 'Line', 'Style'), wt_var = 'Qty')

If you don't have the plyr-package yet, run install.packages('plyr') first.

Emil Bode
  • 1,784
  • 8
  • 16