df2
Hotel_ID Review_date Negative_Rev Positive_Rev Negative Positive
1 2015/08/20 bad staff comfortable room 1 1
1 2015/08/30 No Negative good staff 0 1
2 2015/09/24 no staff No Positive 1 1
2 2016/02/03 No Breakfast near city centre 1 1
2 2016/03/22 No Negative No Positive 0 0
Negative
和
Positive
变量基于
Negative_Rev
和
Positive_Rev
x = 0 if No Negative or No Positive
).
df2
Hotel_ID
和
Review_Date
并创建两个新列,称为
Daily_Negative
Daily_Positive
派生自
cumsum
分别的功能
消极的
积极乐观的
.
例如,我试过这样做:
> df$Daily_Positive <- ddply(df, .(Review_Date, Hotel_ID), transform, Daily_Positive = cumsum(Positive))