I have the following dataframe
FileNumber<-c("510708396","510708396","510708396","510708485","510667325")
EventCode<-c("CASCRT","DISCSENT","DISCSENT","CASCRT","DISCSENT")
EventDate<-c("8/21/2018 12:00:00 AM","12/3/2018 2:41:18 PM","12/3/2018 3:50:16 PM","8/23/2018 12:00:00 AM","12/12/2018 9:11:28 AM")
df<-data.frame(FileNumber,EventCode,EventDate)
FileNumber EventCode EventDate
1 510708396 CASCRT 8/21/2018 12:00:00 AM
2 510708396 DISCSENT 12/3/2018 2:41:18 PM
3 510708396 DISCSENT 12/3/2018 3:50:16 PM
4 510708485 CASCRT 8/23/2018 12:00:00 AM
5 510667325 DISCSENT 12/12/2018 9:11:28 AM
I want to change this long format dataframe into a wide format data with using EventCodes CASRT
and DISCSENT
as the column names. I tried the following
library(reshape2)
dcast(df,FileNumber~EventCode,value.var = "EventDate")
however I recieve the following and a message that "Aggregation function missing: defaulting to length" where as I was expecting the EventDate
values.
FileNumber CASCRT DISCSENT
1 510667325 0 1
2 510708396 1 2
3 510708485 1 0
I'm guessing this has something do to do with the non-unique values in the FileNumber
how do I make sure that I get the Event Date values instead of 1's and 0's.