Using R and dplyr, I have an aggregated dataframe with sentiment scores per day and per user:
date | user | sentiment_score | anger | fear | trust
2016-12-15 | x | -1 | 2 | 1 | 0
2016-12-16 | x | -1 | 0 | 0 | 0
2016-12-15 | y | 1 | 0 | 1 | 0
2016-12-16 | y | -1 | 3 | 0 | 0
2016-12-15 | z | 0 | 0 | 0 | 0
Dput:
df <- structure(list(created_at = structure(c(17150, 17151, 17150,
17151, 17150), class = "Date"), user = c("x", "x", "y", "y",
"z"), sentiment_score = c(-1, -1, 1, -1, 0), anger = c(2, 0,
0, 3, 0), fear = c(1, 0, 1, 0, 0), trust = c(0, 0, 0, 0, 0)), .Names = c("created_at",
"user", "sentiment_score", "anger", "fear", "trust"), class = "data.frame", row.names = c("1900961",
"1900971", "1900981", "1900991", "1901001"))
For prediction purposes I would like to transform this dataframe to a dataframe per day with seperate sentiment score columns for each user (ending up with many columns):
date | x_sentiment_score | x_anger | x_fear | x_trust| y_sentiment_score | y_anger | y_fear | y_trust| z_sentiment_score | z_anger | z_fear | z_trust
2016-12-15 | -1 | 2 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0
2016-12-16 | -1 | 0 | 0 | 0 | -1 | 3 | 0 | 0 | 0 | 0 | 0 | 0
I am puzzled how to achieve this. Any advice would be greatly appreciated.