Re: [R] Creating dummy variable using ifelse statement while you also retain NA's

2016-08-17 Thread William Dunlap via R-help
You can use nested ifelse() calls, as in x <- c("a", "b", NA, "678") ifelse(is.na(x), NA_integer_, ifelse(grepl("[a-z]", x), 1L, 0L)) #[1] 1 1 NA 0 Note that most modelling functions that need dummy variables use the model.matrix function internally so character/factor data gets co

Re: [R] Creating dummy variable using ifelse statement while you also retain NA's

2016-08-17 Thread Jeff Newmiller
I cannot imagine why you would want ifelse to support an na.rm argument, and your phrase 'still retains the missing data denoted as "NA"' seems exactly how ifelse works anyway. You may need to study how NA values work... basic things like TRUE & NA ==NA and when you should use is.na(). The"Intr

[R] Creating dummy variable using ifelse statement while you also retain NA's

2016-08-17 Thread Olu Ola via R-help
Hello,I am trying to create a dummy variable using the ifelse statement. However, the ifelse statement does not recognize na.rm = True. How can I create a dummy variable so that it still retains the missing data denoted as "NA" ? Regards [[alternative HTML version deleted]]