我有一个二进制字符串的向量:
a<-c(0,0,0,1,0,1)
Run Code Online (Sandbox Code Playgroud)
我想将此向量转换为十进制.
我尝试使用compositions包和unbinary()函数,但是,此解决方案以及我在此站点上找到的大多数其他解决方案都需要g-adic字符串作为输入参数.
我的问题是如何将矢量而不是字符串转换为十进制?
说明问题:
library(compositions)
unbinary("000101")
[1] 5
Run Code Online (Sandbox Code Playgroud)
这给出了正确的解决方案,但是:
unbinary(a)
unbinary("a")
unbinary(toString(a))
Run Code Online (Sandbox Code Playgroud)
产生NA.