SPSSからRに変換しようとしています。私はRを学ぶ良い方法として私の掃除構文を翻訳したいと思っていましたが、私はSPSSの単純なコマンドとは何か大きな問題を抱えています。多数の変数を多くの変数やステートメントで1つの変数に再コード化する
次のコードは、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_ethするn_ethnicityと改名することに注意してください)同じではありません。私は大いに助けていただければ幸いです!ありがとう!
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
。 'OMSOct14_Mar16 $ race_eth [OMSOct14_Mar16 $ n_race == 2] < - 3' – thelatemail
のように、変数が明示的に指定するデータセットを参照し続ける必要があります。脇に、' n_ethnicity = 2 | n_ethnicity = 4 | n_ethnicity = 5'は%c(2,4,5) 'のn_ethnicity%に変換することができます。これはずっと簡単です。 – thelatemail
何らかの理由で99という値が7になったことに気付きませんでした。ラベルを貼るときにRが変数を注文すると思いますか?それは働いて、簡素化のためにあなたに感謝!私は自分でそれを非常に難しくしていました。 – KCP