I have a dateframe with the following data:
#sample data
Date <- c( "2020-01-01", "2020-01-01", "2020-01-01", "2020-01-01", "2020-01-01", "2020-01-02", "2020-01-02", "2020-01-02", "2020-01-02")
Salesperson <-c ( "Sales1", "Sales1", "Sales1", "Sales2", "Sales2", "Sales1", "Sales1", "Sales2", "Sales2" )
Clothing <-c ( "5", "2", "8", "3", "3", "4", "7", "3", "4" )
Electronics <-c ( "6", "9", "1", "2", "1", "2", "2", "1", "2" )
data<-data.frame(Date,Salesperson,Clothing,Electronics, stringsAsFactors = FALSE)
data$Date<-as.Date(data$Date,"%Y-%m-%d")
There are rows in the df where a salesperson have recorded their sales multiple times for the same date rather than adding them up.
The result I want is shown by the dataframe below:
Date <- c ( "2020-01-01", "2020-01-01", "2020-01-02", "2020-01-02" )
Salesperson <- c ( "Sales1", "Sales2", "Sales1", "Sales2")
Clothing <- c ( "15", "6", "11", "7" )
Electronics <- c ( "16", "3", "4", "3" )
data1<-data.frame(Date,Salesperson,Clothing,Electronics, stringsAsFactors = FALSE)
Does anyone know how to achieve this result?