I have a data.frame
where I need to extract values into their own variables (columns), but keep the integrity of the unique identifier, so that there is only one unique ID per observation (row). I have tried using group_by()
, mutate
, and spread
to no avail. I have tried using dcast
and melt
but must be missing something. I have also tried solutions posted here, here, and here, but none of them seem to work for my situation.
My data.frame
looks like this;
UID<-c(rep(1:25, 2), rep(26:50, 2))
Group<-c(rep(5, 25), rep(20, 25), rep(-18, 25), rep(-80, 25))
Value<-sample(100:5000, 100, replace=TRUE)
df<-data.frame(UID, Group, Value)
Please help me figure out how extract these values to one unique ID per line (see expected output image arranged by UID here). If it is easier the empty values can be NULL, NA, or 0 (yes really actually zero).