已为我提供了要对其执行逻辑回归的数据集。但是,为此,我需要在R中合并一些列。
例如,在看护评估数据集中,我得到了(BuyingPrice_low,BuyingPrice_medium,BuyingPrice_high,Buyinging_vhigh,MaintenancePrice_low,MaintenancePrice_medium,MaintenancePrice_high,MaintenancePrice_vhigh)
如何将购买price_low,medium等列合并到一个名为“ BuyingPrice”的列中,该列中的订单及其各自的数据以及与maintenanceprice列相同?
答案 0 :(得分:0)
library(dplyr)
df <- data.frame(Buy_low=rep(c(0,1), 10),
Buy_high=rep(c(0,1), 10))
one_column <- df %>%
gather(var, value)
head(one_column)
var value
1 Buy_low 0
2 Buy_low 1
3 Buy_low 0
4 Buy_low 1
5 Buy_low 0
6 Buy_low 1
答案 1 :(得分:0)
可以通过在基数R中的select CustomerID, date as active_date, inactive_date
from (select t.*,
min(case when activity = 'Inactive' then date end) over (partition by CustomerID order by date desc) as inactive_date
from t
) t
where activity = 'Active';
来完成:
stack