0

I have an R data frame in this form with thousands of records:

account_id             timestamp    days_since_launch   region  used
    1263562             6/23/16           5               SFO    57
    3821750             6/24/16           11              ATL    10

I want to convert it into a form, where the column names are:

account_id    timestamp  days_since_launch  SFO ATL SEA NYC SLC 

Note: In here the columns SFO, ATL, SEA, NYC, SLC are the unique entries of region in the original dataset. I want the entries in these region columns to have the corresponding numeric entry in used.

How can this be done in R?

I tried as.data.frame(acast(inputDF, account_id + timestamp ~ region, value.var="used"))

The issue I have with this is: it forms a column name called account_id_timestamp with the account id's and timestamps concatenated like 1263562_6/23/16 . It also gives a warning: "Aggregation function missing: defaulting to length"

Psidom
  • 209,562
  • 33
  • 339
  • 356
hearse
  • 379
  • 2
  • 4
  • 23

0 Answers0