Sorry, I noticed my previous code does not work if a column has all NAs. Try this instead:
dat <- matrix(as.logical(sample(T:F, 30, T)),5,6) colnames(dat) <- letters[1:6] rownames(dat) <- paste(letters[1:5],1:5, sep="") dat1 <- matrix(NA,5,6) colnames(dat1) <- colnames(dat) rownames(dat1) <- rownames(dat) dat1[dat] <- unlist(sapply(apply(dat,2,sum), function(x) {if(x > 0) {seq(x)} else {list()}})) -- View this message in context: http://n4.nabble.com/Filling-a-logical-matrices-with-values-tp1469365p1470775.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.