A: Tidyverse's summarize can be use. Sample below.
Requirement: Remove duplicates and merge data (rows) at the same time.
Sample data
Expected output after merging
Output when we use Excel's Remove Duplicates. Data is lost
Output using R, we get the expected output
Code:
library(tidyverse)
library(readxl)
sampleContainer<-read_excel("SampleContainers.xlsx")
cleanData<-sampleContainer %>%
group_by(ReferenceNumber, ContainerNumber) %>%
summarize(lastPullOutadvise=first(PullOutAdvice, order_by = PullOutAdvice),
lastPullOutCY=first(PullOutCY, order_by = PullOutCY ))
library(tidyverse)
library(readxl)
sampleContainer<-read_excel("SampleContainers.xlsx")
cleanData<-sampleContainer %>%
group_by(ReferenceNumber, ContainerNumber) %>%
summarize(lastPullOutadvise=first(PullOutAdvice, order_by = PullOutAdvice),
lastPullOutCY=first(PullOutCY, order_by = PullOutCY ))
No comments:
Post a Comment