digitsBase(sfsmisc)
digitsBase()所属R语言包:sfsmisc
Digit/Bit Representation of Integers in any Base
数字/位整数的表示在任何碱基
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Integer number representations in other Bases.
在其他碱基的整数数字表示。
Formally, for every element N =x[i], compute the (vector of) “digits” A of the base b representation of the number N, N = sum(k = 0:M ; A[M-k] * b^k).<br> Revert such a representation to integers.
从形式上看,每一个元素N =“x[i],计算(矢量)”数字“Abaseb的数字表示<X >,N。<BR>恢复这样的表示为整数。
用法----------Usage----------
digitsBase(x, base = 2, ndigits = 1 + floor(log(max(x),base)))
## S3 method for class 'basedInt'
as.integer(x, ...)
## S3 method for class 'basedInt'
print(x, ...)
as.intBase(x, base = 2)
参数----------Arguments----------
参数:x
For digitsBase(): non-negative integer (vector) whose base base digits are wanted. For as.intBase(): <br> a list of numeric vectors, a character vector, or an integer matrix as returned by digitsBase(), representing digits in base base.
对于digitsBase():非负整数(矢量),其基极base想要数字。对于列表中的数值变量,一个字符向量,或者一个整数矩阵返回的as.intBase(),代表数字的基础digitsBase()base:<BR>的。
参数:base
integer, at least 2 specifying the base for representation.
整数,至少有2个指定用于表示的基。
参数:ndigits
number of bits/digits to use.
使用的比特/数字的数量。
参数:...
potential further arguments passed to methods, notably print.
潜在的进一步传递给方法的参数,特别是print。
值----------Value----------
For digitsBase(), an object, say m, of class "basedInt" which is basically a (ndigits x n) matrix where m[,i] corresponds to x[i], n <- length(x) and attr(m,"base") is the input base.
对于digitsBase(),一个对象,说m,类"basedInt"这基本上是一个(ndigitsXn)matrix其中<X >m[,i],x[i]和,“n <- length(x)是输入attr(m,"base")。
as.intBase() and the as.integer method for basedInt objects return an integer vector.
as.intBase()和as.integer方法basedInt对象返回一个integer向量。
注意----------Note----------
digits and digits.v are now deprecated and will be removed from the sfsmisc package.
digits和digits.v现已过时,将被删除sfsmisc包。
(作者)----------Author(s)----------
Martin Maechler, Dec 4, 1991 (for S-plus; then called <code>digits.v</code>).
实例----------Examples----------
digitsBase(0:12, 8) #-- octal representation[ - 八进制表示]
empty.dimnames(digitsBase(0:33, 2)) # binary[二进制]
## This may be handy for just one number (and default decimal):[#这可能是方便的只是一个数字(默认小数):]
digits <- function(n, base = 10) as.vector(digitsBase(n, base = base))
digits(128, base = 8) # 2 0 0[2 0 0]
## one way of pretty printing (base <= 10!)[#一个漂亮的印刷方式(碱基<= 10!)]
b2ch <- function(db)
noquote(gsub("^0+(.{1,})$"," \\1",
apply(db, 2, paste, collapse = "")))
b2ch(digitsBase(0:33, 2)) #-> 0 1 10 11 100 101 ... 100001[ - > 0 1 10 11 100 101 ... 100001]
b2ch(digitsBase(0:33, 4)) #-> 0 1 2 3 10 11 12 13 20 ... 200 201[ - > 0 1 2 3 10 11 12 13 20 ... 200 201]
## Hexadecimal:[#十六进制:]
i <- c(1:20, 100:106)
M <- digitsBase(i, 16)
hexdig <- c(0:9, LETTERS[1:6])
cM <- hexdig[1 + M]; dim(cM) <- dim(M)
b2ch(cM) #-> 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 ... 6A[ - > 1 2 3 4 5 6 7 8 9 ABCDEF 10 11 ... 6A]
## Inverse of digitsBase() : as.integer method for the "basedInt" class[#逆向的digitsBase():as.integer的方法为的“basedInt的”类]
as.integer(M)
## or also as.intBase() working from strings:[#或as.intBase()从字符串的工作:]
(cb <- apply(digitsBase(0:33, 4), 2, paste, collapse = ""))
##-> "000" "001" ..... "200" "201"[# - >“000”,“001”...... “200”“201”]
all(0:33 == as.intBase(cb, base = 4))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|