Here's a possible solution. dd <- structure(list(a = c(TRUE, FALSE, FALSE), b = c(TRUE, FALSE, TRUE), c = c(TRUE, FALSE, FALSE), d = c(TRUE, TRUE, FALSE)), .Names = c("a", "b", "c", "d"), row.names = c(NA, -3L), class = "data.frame")
ds <- as.data.frame(t(apply(!dd, 1, cumsum)-apply(dd, 1, cumsum))) ds[as.matrix(dd)] <- 0 ds Best, Nello -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Camilo Mora Sent: Mittwoch, 27. März 2013 09:32 To: r-help@r-project.org Subject: [R] conditional Dataframe filling Hi everyone: This may be trivial but I just have not been able to figure it out. Imagine the following dataframe: a b c d TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE FALSE TRUE FALSE FALSE I would like to create a new dataframe, in which TRUE gets 0 but if false then add 1 to the cell to the left. So the results for the example above should be something like: a b c d 0 0 0 0 1 2 3 0 1 0 1 2 I wonder if you may know?. Thanks, Camilo Camilo Mora, Ph.D. Department of Geography, University of Hawaii Currently available in Colombia Phone: Country code: 57 Provider code: 313 Phone 776 2282 From the USA or Canada you have to dial 011 57 313 776 2282 http://www.soc.hawaii.edu/mora/ ______________________________________________ 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. ______________________________________________ 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.