将二进制变量更改为是/否 [英] Changing binary variables to Yes/No
本文介绍了将二进制变量更改为是/否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个要分析的数据框.问题在于,数据帧中有一堆1和0(不是,是1)是(是,0是否).如何修改数据框以使其为1和0,而不是1和0,所以我可以使用逻辑回归?我敢肯定有一个简单的解决方法,我没有想到
So I have a data frame that I'd like to analyze. The problem is that instead of Yes/No, there are a bunch of 1s and 0s (1 being Yes, 0 being No) in the data frame. How do I modify the data frame to make it so instead of the 1s and 0s there are Yes and No so I can use logistic regression? I am sure there is a simple fix for this that I am not thinking of
谢谢!
推荐答案
使用?factor
.
查看此示例
> set.seed(1)
> dummyVariable <- sample(c(0,1), 10, TRUE) # bunch of 0 and 1
> newVariable <- factor(dummyVariable, levels=c(0,1), labels=c("No", "Yes"))
> newVariable # this is now a dummy variable ready for regression analysis
[1] No No Yes Yes No Yes Yes Yes Yes No
Levels: No Yes
这篇关于将二进制变量更改为是/否的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文