[R] Filling a logical matrices with values

Paul- paul at aurynia.com
Fri Feb 5 21:51:57 CET 2010


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.



More information about the R-help mailing list