我正在尝试从 SPSS 转换为 R;我想将我的清理语法翻译为学习 R 的好方法,但我在 SPSS 中的简单命令方面遇到了很多麻烦。
以下代码在 SPSS 中有效:
IF (n_race = 1 & (n_ethnicity = 7 | n_ethnicity = 8 | n_ethnicity = 99)) race_eth=1.
EXECUTE.
IF (n_ethnicity = 3 & (n_race = 1 | n_race = 99)) race_eth=2.
EXECUTE.
IF (n_race = 2) race_eth=3.
EXECUTE.
IF (n_race = 5 & n_ethnicity NE 9) race_eth=4.
EXECUTE.
IF ((n_ethnicity = 2 | n_ethnicity = 4 | n_ethnicity = 5) & (n_race = 1 | n_race = 99)) race_eth=4.
EXECUTE.
IF (n_ethnicity = 9 & (n_race = 1 | n_race = 5 | n_race = 99)) race_eth=5.
EXECUTE.
IF (n_race = 4 | (n_ethnicity = 6 & (n_race = 1 | n_race = 99))) race_eth=6.
EXECUTE.
IF (n_ethnicity = 1 & (n_race = 1 | n_race = 99)) race_eth=6.
EXECUTE.
IF (n_race=99 AND (n_ethnicity=7 OR n_ethnicity=99 OR n_ethnicity=8)) race_eth=99.
EXECUTE.
我认为这段代码在 R 中会做同样的事情,但是单元频率不一样(注意我在 R 中将 n_ethnicity 重命名为 n_eth)。我将不胜感激任何帮助!谢谢!
OMSOct14_Mar16$race_eth[n_race == 1 & (n_eth == 7 | n_eth == 8 | n_eth == 99)] <- 1
OMSOct14_Mar16$race_eth[n_eth == 3 & (n_race == 1 | n_race == 99)] <- 2
OMSOct14_Mar16$race_eth[n_race == 2] <- 3
OMSOct14_Mar16$race_eth[n_race == 5 & n_eth != 9] <- 4
OMSOct14_Mar16$race_eth[(n_eth == 2 | n_eth==4 | n_eth==5) & (n_race == 1 | n_race == 99)] <- 4
OMSOct14_Mar16$race_eth[n_eth == 9 & (n_race == 1 | n_race == 5 | n_race==99)] <- 5
OMSOct14_Mar16$race_eth[n_race == 4 | (n_eth == 6 & (n_race==1 | n_race == 99))] <- 6
OMSOct14_Mar16$race_eth[n_eth == 1 & (n_race == 1 | n_race == 99)] <- 6
OMSOct14_Mar16$race_eth[n_race == 99 & (n_eth == 7 | n_eth == 8 | n_eth==99)] <- 99