如何在RStudio中创建虚拟变量?有数字数据?

时间:2015-03-10 02:08:03

标签: rstudio dummy-data

JOB 0:失业/非熟练 - 非居民 1:不熟练 - 居民 2:熟练的员工/官员 3:管理/自雇/高素质的员工/官员 历史 0:没有学分 1:该银行的所有信用均已正式偿还 2:现有的学分到目前为止已经还清 3:过去延迟付款 4:关键帐户

1 个答案:

答案 0 :(得分:0)

首先:RStudio是一个IDE(集成开发环境)。您可能想要使用R(RStudio使用的语言/统计程序,但也可以单独使用)。

您的问题非常明确,但如果(我不确定)您正在寻找使用虚拟变量的方法,例如回归模型,您可以考虑使用因子变量:< / p>

JOB <- factor(sample(1:3, 10, replace = TRUE), 
              levels= 0:3,
              labels = c("unemployed/ unskilled - non-resident",
                         "unskilled - resident",
                         "skilled employee / official",
                         "management/ self-employed/highly qualified employee/ officer"),
              ordered = TRUE
)

将会给你:

 [1] unskilled - resident                                        
 [2] unskilled - resident                                        
 [3] skilled employee / official                                 
 [4] skilled employee / official                                 
 [5] skilled employee / official                                 
 [6] unskilled - resident                                        
 [7] management/ self-employed/highly qualified employee/ officer
 [8] unskilled - resident                                        
 [9] skilled employee / official                                 
[10] management/ self-employed/highly qualified employee/ officer
4 Levels: unemployed/ unskilled - non-resident < unskilled - resident < ... < management/ self-employed/highly qualified employee/ officer

和HISTORY类似。