0

I have a big data file which looks like:

ID Time Value
1 BEG 1.2
1 END 2.2
2 BEG 1.7
2 END 0.5
2 SUP 2.4
3 BEG 3.2

I want to re-organize this data so it looks like:

ID BEG END SUP
1  1.2 2.2 NA
2  1.7 0.5 2.4
3  3.2  NA  NA

In other words, I need the values of time, value and sub to be on the same row for each ID.

MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
Adam Majdi
  • 107
  • 1
  • 1
  • 11

1 Answers1

1

This is a dcast question:

require(data.table)
# Your data frame will be called `df`
dt <- data.table(df)
dt.wide <- dcast(dt, ID ~ Time, value.var = "Value")
akash87
  • 3,876
  • 3
  • 14
  • 30