简体   繁体   English

从另一个因素中添加一个因素

[英]Adding a factor from another factor

I have 5 dichotomous variables (0=no and 1=yes).我有 5 个二分变量(0=否,1=是)。 Selecting 'yes' indicates that a subject stated this behavior is a part of their coping skills (eg, meditation; going for a walk).选择“是”表示受试者表示此行为是他们应对技巧的一部分(例如,冥想;散步)。 I have summed the coping skills variable and then created a factor (0 skills used; 1-2 skills used; 3 or more skills used).我总结了应对技能变量,然后创建了一个因素(使用了 0 个技能;使用了 1-2 个技能;使用了 3 个或更多技能)。

levels(x$var1)
[1] "0"  "1"

Total coping skills factor variable:总应对技能因子变量:

x %>% count(cop.skills)
# A tibble: 3 x 2
  str.12     n
  <fct>  <int>
1 0       3743
2 1-2     4398
3 3+      2632

There's a sixth dichotomous variable asking, "I have never done any of these behaviors (listed above)," with a dichotomous answer (0=no and 1=yes).第六个二分变量询问“我从未做过任何这些行为(上面列出的)”,答案是二分法(0=否,1=是)。

 x %>% count(var6)
# A tibble: 2 x 2
  stress2     n
  <fct>   <int>
1 0       11456
2 1          77

I would like to add the "yeses" to the "0" level of cop.skills variable.我想将“yeses”添加到 cop.skills 变量的“0”级别。 "cop.skills" would look like this: “警察技能”看起来像这样:

x %>% count(cop.skills)
# A tibble: 3 x 2
  str.12     n
  <fct>  <int>
1 0       3820
2 1-2     4398
3 3+      2632

Not sure how to do this.不知道该怎么做。

Why not just add them to your first result?为什么不将它们添加到您的第一个结果中呢?

result    <- x %>% count(cop.skills)
no_skills <- x %>% count(var6)
result[1, 2] <- result[1, 2] + no_skills[2, 2]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM