Re: [R] Create variable with AND IF statement

2012-01-03 Thread Richard Kolodziej
Hello, thanks for the quick answers! Some answers were more useful to me than others but I really appreciate everybodys effort, reading and answering my question. I will try Dons approach because as he said, it looks quite readable. I'll need to take a closer look on the nested ifelse statements

Re: [R] Create variable with AND IF statement

2012-01-02 Thread David Winsemius
On Jan 2, 2012, at 4:22 PM, David Stevens wrote: Could it be NO. You are not reading the documentation for "if" carefully enough, despite several efforts to point you in the right direction. You cannot make literal transliterations of SPSS syntax work in the manner you imagine. -- Dav

Re: [R] Create variable with AND IF statement

2012-01-02 Thread David Stevens
Could it be if(variable1.fac == 0 & variable2.num == 0) {variable3 = 1} # brackets {} aren't strictly required for a one liner. if(variable1.fac == 0 & variable2.num >= 0) {variable3 = 2} # brackets {} aren't strictly required for a one liner. if(variable1.fac == 1 & variable2.nu

Re: [R] Create variable with AND IF statement

2012-01-02 Thread MacQueen, Don
I usually do this kind of thing like this: variable3 <- rep(1,length(variable1.fac)) variable3[ variable1.fac == 0 & variable2.num >= 1 ] <- 2 variable3[ variable1.fac == 1 & variable2.num == 0 ] <- 3 variable3[ variable1.fac == 1 & variable2.num >= 1 ] <- 4 This approach is easy to read and unde

Re: [R] Create variable with AND IF statement

2012-01-02 Thread David Winsemius
On Jan 2, 2012, at 10:42 AM, David Winsemius wrote: On Jan 2, 2012, at 4:11 AM, Richard Kolodziej wrote: Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is qu

Re: [R] Create variable with AND IF statement

2012-01-02 Thread ONKELINX, Thierry
d Kolodziej Verzonden: maandag 2 januari 2012 10:11 Aan: r-help@r-project.org Onderwerp: [R] Create variable with AND IF statement Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck wi

Re: [R] Create variable with AND IF statement

2012-01-02 Thread David Winsemius
On Jan 2, 2012, at 4:11 AM, Richard Kolodziej wrote: Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS-Syntax: IF (var

[R] Create variable with AND IF statement

2012-01-02 Thread Richard Kolodziej
Hello, I'm using SPSS at work but really would like to switch to R. Right now I'm trying to learn R in reproducing calculations I did with SPSS but am stuck with something that is quite simple and comprehensible in SPSS-Syntax: IF (variable1.fac = 0 AND variable2.num = 0) variable3=1. IF (variabl