Dear R-help members,

I'm processing a large amount of MODIS data where quality assessment 
information is stored as an integer value for each pixel. I have to 
converted this number to an 8 digit binary flag to get access to the 
stored quality code (e.g. in2bin(165,8) = 1 0 1 0 0 1 0 1).

Unfortunately, I did not manage to find a package providing a fast 
function to do so. I need to run this on millions of pixels and thus 
wrote the following function.

int2bin <- function(x,ndigits){
     base <- array(NA, dim=c(length(x), ndigits))
     for(q in 1:ndigits){
           base[, ndigits-q+1] <- (x %% 2)
           x <- (x %/% 2)
       }
     bin<- apply(base,1,paste,collapse="")
     return(bin)
}

Since it is still slow, I have to find a way to express this more 
elegantly. I'd really appreciate any help.

Thanking you, with best regards

Jonas Jägermeyr

Potsdam Institute for Climate Impact Research
Research Domain II

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to