HI, May be this helps: set.seed(45) dat1 <- as.data.frame(matrix(sample(0:1,100*5,replace=TRUE),ncol=5))
dat1$Newvar <- 1*(!!rowSums(dat1)) A.K. Hello. I have a problem combining a number of variables. I have five columns with binary variables with the values 0 and 1. I would like to combine them into just one binary variable with 1 whenever just one of the other has value one, and 0 if none of them have value one. How can I do that? I tried to use cbind function, but for some reason I get results 1 even though all of the varuables included = 0 and for some rows I get 2. I tried changing the deparse.level but that doesn't seem to be the problem. I hope someone can help. Kind regards ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.