Trying to do something so simple and transpose this data wide so for each ID I have the VisitNum {1,2,3} as the column header and the CollectionDate as the value.
At my starting point Collection date was a character variable and VisitNum was numeric. I've tried with them as imported and with different formats after this code:
visit2$CollectionDate <- as.Date(visit2$CollectionDate, "%m-%d-%Y")
visit2$VisitNum <- as.character(visit2$VisitNum)
I've tried with dcast
and got the below results. It's the dataframe I want but the date's aren't formatted anymore.
visit_long_a<- dcast(visit2, ParticipantID ~ VisitNum, value.var = "CollectionDate")
Aggregation function missing: defaulting to length
and with reshape
and got even more bizarre results. I don't understand why the column is being concatenated.
visit_long_a <- reshape(visit2, direction = "wide", idvar = "ParticipantID", timevar = "VisitNum")