Re: [R] adding column to data frame conditionally

2010-05-27 Thread Stephan Kolassa
Hi Kristina, Thierry's solution is certainly the "correct" one in terms of keeping within R's philosophy... but I personally find a series of conditional assignments easier to understand - see below for an example. HTH, Stephan # # Example

Re: [R] adding column to data frame conditionally

2010-05-27 Thread Kristina Schmitz
Dear Thierry, thank you so much! Quoting "ONKELINX, Thierry" : Dear Kristina, Use ifelse(). Note that you must use '==' to test for equality. '=' is an assignment. Freqg$condition <- with(freqg, ifelse(mat==1 & flank==1, 1, ifelse(mat == 2 & flank == 1, 2, NA))) HTH, Thierry -

Re: [R] adding column to data frame conditionally

2010-05-27 Thread ONKELINX, Thierry
Dear Kristina, Use ifelse(). Note that you must use '==' to test for equality. '=' is an assignment. Freqg$condition <- with(freqg, ifelse(mat==1 & flank==1, 1, ifelse(mat == 2 & flank == 1, 2, NA))) HTH, Thierry ir.