0
我想彙總並報告下面每個BOM的WW的最小值和最大值。R爲實體的每個值彙總最小值和最大值的編程
BOM = c("A","A","A","A","A","B","B","B","B","B","C","C","C","C")
WW = c("201305","201306","201308","201310","201311","201345","201346","201347","201349","201352","201336","201337","201339","201341")
df <- data.frame(BOM,WW)
我試圖這樣做以下,但不幸的是我得到了全球最小和最大WW,不是針對每個單獨的BOM,我想它。
df <- group_by(df, BOM)
extremes <- summarise(df, minw=min(as.numeric(WW)), maxw=max(as.numeric(WW)))
你能幫忙嗎? 下面是我期待如果代碼正常工作的最終結果。
BOM= c("A","B","C")
minWW = c("201305","201345","201336")
maxWW = c("201311","201352","201341")
df2 <-data.frame(BOM,minWW,maxWW)
非常感謝。
你爲什麼要建立WW爲特徵向量?或者他們是否是日期? – Jav
您可以檢查是否還加載了「plyr」。如果是這種情況,請使用'dplyr :: summarize(df,....'應該可以解決它(因爲函數被屏蔽) – akrun
謝謝,這也起到了作用 – GabStacker