我对tidyverse中的因子和新变量之间的区别有些困惑。我正在尝试根据某人的报纸是否支持某项政策(在本例中为欧盟)来创建一个新变量。我尝试使用mutate
和fct_collapse
,如下所示。
joint%>%
mutate(grouped = fct_collapse(Paper_Before, Pro_Eu = c("grauniad","Independent", "FT"),
Anti_Eu = c("Telegraph", "Daily Mail"),
Times ="Times",
Rest = c("Sun", "Others", "Daily Mirror", "Daily Star", "Daily Express")))
grouped_newspapers <- joint %>%
select(grouped, EU_Vote_Intent_Before, EU_Vote_Intent_After)
任何帮助将不胜感激!
My data can be found with this link.
为了清楚起见,我将Papers_before的10种不同的论文归为4个新类别,但不是tidyverse认为这是一个新专栏,它只是将其视为一个因素:我认为我对这个概念基本上有误解!