当前位置:网站首页>R language bug? report errors? As for the outcome of sub variables 0 and 1, the original content of the outcome variable is changed through the process of factor and numeric?

R language bug? report errors? As for the outcome of sub variables 0 and 1, the original content of the outcome variable is changed through the process of factor and numeric?

2022-06-21 18:40:00 Illegal account 247188

problem RT

Because I'm doing PSM Inverse probability weighted sum matching method , And chi square test when making tables , Their requirements for the type of outcome variables are different , I am in the process of transformation , Find out outcome Content 0 1 become 12 , Although they are 0=1 、1=2 Has little effect on the transformation of , But I'm extracting hierarchically outcome=0 when , Want to extract the control group , No corresponding data is found . So this bug How did it come about ?

data <- iris # Iris 
data$outcome <- rep(0:1,each=75)
table(data$outcome)
str(data$outcome)
#outcome Factorization 
data$outcome <- as.factor(data$outcome)  
table(data$outcome) # here outcome still  0 and 1
str(data$outcome)
#outcome Continue to convert to numerical type 
data$outcome <- as.numeric(data$outcome)
table(data$outcome)  # At this time, I found out outcome  01 The Subvariable becomes 1 and 2
str(data$outcome)
#【 problem ,outcome Variable pass factor and numeric The process , Changed the original content ?

 Insert picture description here

原网站

版权声明
本文为[Illegal account 247188]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211659281701.html