1

I'd like to manipulate data in R as follows, can anybody help please?

Before:

Record  Person  Value
1       1       100
1       2       0
1       3       200
2       1       150
2       2       220

After:

Record  Value
1       {100, 0, 200}
2       {150, 220}

Ideally I'd like the final dataset values to be in a list (as opposed to a string), so that I can apply formulas to each value.

Many thanks in advance.

Sotos
  • 51,121
  • 6
  • 32
  • 66
Jason
  • 13
  • 2

1 Answers1

0

You can try the following code

dfout <- aggregate(Value~Record, df, toString)

or

dfout<- aggregate(Value~Record, df,FUN = function(x) x)

such that

> dfout
  Record       Value
1      1 100, 0, 200
2      2    150, 220

DATA

df <- structure(list(Record = c(1L, 1L, 1L, 2L, 2L), Person = c(1L, 
2L, 3L, 1L, 2L), Value = c(100L, 0L, 200L, 150L, 220L)), class = "data.frame", row.names = c(NA, 
-5L))
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81