[R] (no subject)
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Thu Feb 5 13:35:20 CET 2004
meriema.aupetit at free.fr writes:
> Hello,
> Splus contains the function intbin(x,l).
>
> This function allows to make a conversion from an integer x to a binary of
> length l.
>
> for example
>
> intbin(3,2) returns 11
>
> intbin(3,3) returns 011
>
> Do you know how to do it in R ?
How about this?
intbin <- function(x, n)
if(n)
paste(intbin(x%/%2, n-1), x%%2, sep="")
else if (x)
stop("Insufficient field width")
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list