Re: [R] help calculating variable based on factor level of another

2010-05-27 Thread Joshua Wiley
Sorry that last bit of code was redundant, it should be: x2 <- ifelse(x1=="social and cultural specialists", "1", "0") ifelse() leaves NAs by default so no need to manually do it. On Thu, May 27, 2010 at 7:30 AM, Joshua Wiley wrote: > Dear Simon, > > It is a bit hard to tell what you want witho

Re: [R] help calculating variable based on factor level of another

2010-05-27 Thread Joshua Wiley
Dear Simon, It is a bit hard to tell what you want without a reproducible example, below is my guess. I created x1 as a factor with some data in it based off of what I think you are working with and then x2 from x1. data <- c("social and cultural specialists", "l

Re: [R] help calculating variable based on factor level of another

2010-05-27 Thread Ivan Calandra
Hi, I'm really confused about your question. For many reasons: - because I'm a beginner myself? - what are you trying to do with x1? You define the levels of x1, but you don't give any values to it. Which could (also) explain why your code does not work - your if...else statement is weird for m

[R] help calculating variable based on factor level of another

2010-05-27 Thread Simon Kiss
Dear colleagues, I want to calculate the value of x2 based on the value of x1. x1 is a factor with three separate levels. I want to make sure that missing values remain as NA in X2, but non-missing values take on a value of either 0 or 1 dependending on the value in x1. This is the code I'm wo