R 客户状态连接字符串
R Customer state concatenate string
我想使用 levenshtein 距离来计算客户的行为,以及客户每年所处的状态与以前的状态相关联。
在 Tableau 中,我计算了以下列来显示每年的客户可以是:(不是客户(Not),新客户(New),相同的收入(Same),更少的收入(Down),更多收入 (UP) 和失效 (Lapsed)。
现在我想显示 2019 年的客户并查看他的历史记录,如下所示:NOT-NEW-UP-UP-SAME-SAME-DOWN 并提取 2019 年的客户 table年客户计算 levenshtein。
Costomer - Year - Customer State
Apple 2012 NOT
Apple 2013 NOT
Apple 2014 NEW
Apple 2015 UP
Apple 2016 DOWN
Apple 2017 LAPSED
Apple 2018 RETURN
Costomer - Year - Customer State - Cust. concatenated
Apple 2012 NOT NOT
Apple 2013 NOT NOT-NOT
Apple 2014 NEW NOT-NOT-NEW
Apple 2015 UP ..
Apple 2016 DOWN ..
Apple 2017 LAPSED ..
Apple 2018 RETURN NOT-NOT-NEW-UP-DOWN-LAPSED-RETURN
非常感谢您的帮助!
您可以将 Reduce
与参数 accumulate = TRUE
一起使用,即
Reduce(paste, df$Customer_State, accumulate = TRUE)
#[1] "NOT" "NOT NOT" "NOT NOT NEW" "NOT NOT NEW UP" "NOT NOT NEW UP DOWN" "NOT NOT NEW UP DOWN LAPSED" "NOT NOT NEW UP DOWN LAPSED RETURN"
我想使用 levenshtein 距离来计算客户的行为,以及客户每年所处的状态与以前的状态相关联。
在 Tableau 中,我计算了以下列来显示每年的客户可以是:(不是客户(Not),新客户(New),相同的收入(Same),更少的收入(Down),更多收入 (UP) 和失效 (Lapsed)。
现在我想显示 2019 年的客户并查看他的历史记录,如下所示:NOT-NEW-UP-UP-SAME-SAME-DOWN 并提取 2019 年的客户 table年客户计算 levenshtein。
Costomer - Year - Customer State
Apple 2012 NOT
Apple 2013 NOT
Apple 2014 NEW
Apple 2015 UP
Apple 2016 DOWN
Apple 2017 LAPSED
Apple 2018 RETURN
Costomer - Year - Customer State - Cust. concatenated
Apple 2012 NOT NOT
Apple 2013 NOT NOT-NOT
Apple 2014 NEW NOT-NOT-NEW
Apple 2015 UP ..
Apple 2016 DOWN ..
Apple 2017 LAPSED ..
Apple 2018 RETURN NOT-NOT-NEW-UP-DOWN-LAPSED-RETURN
非常感谢您的帮助!
您可以将 Reduce
与参数 accumulate = TRUE
一起使用,即
Reduce(paste, df$Customer_State, accumulate = TRUE)
#[1] "NOT" "NOT NOT" "NOT NOT NEW" "NOT NOT NEW UP" "NOT NOT NEW UP DOWN" "NOT NOT NEW UP DOWN LAPSED" "NOT NOT NEW UP DOWN LAPSED RETURN"