# [Rd] binary string conversion to a vector (PR#14120)

From: <brglez_at_ncsu.edu>
Date: Wed, 09 Dec 2009 05:35:12 +0100 (CET)

Full_Name: Franc Brglez
Version: R 2.9.1 GUI 1.28 Tiger build 32-bit (5444) OS: MacOSX -- 10.6.2
Submission from: (NULL) (24.148.163.114)

I am demonstrating what may be a bug or my lack of experience. Please review as it would help to hear from someone.
MANY THANKS -- Franc Brglez

The function "binS2binV" returns what I consider a wrong value -- see the terminal output

binS2binV = function(string="0001101", sep="") # this procedure is expected to convert a binary string to a binary vector ... # but does it?? Why do we get a vector with quoted binary values?? {

qlist = strsplit(string, sep)
qvector = qlist[]
cat("\n string=", string)
cat("\n qvector=", qvector)
n = length(qvector) ; xvector = NULL     for (i in 1:n) {

```	tmp = noquote(qvector[i])
cat("\n", i,",     tmp=", tmp)
xvector = c(xvector, tmp)
cat("\n", i,", xvector=", xvector)
```

}
cat("\n")
return(xvector)
}

> print(binS2binV("10101100"))

string= 10101100
qvector= 1 0 1 0 1 1 0 0

``` 1 ,     tmp= 1
1 , xvector= 1
2 ,     tmp= 0
2 , xvector= 1 0
3 ,     tmp= 1
3 , xvector= 1 0 1
4 ,     tmp= 0
4 , xvector= 1 0 1 0
5 ,     tmp= 1
5 , xvector= 1 0 1 0 1
6 ,     tmp= 1
6 , xvector= 1 0 1 0 1 1
7 ,     tmp= 0
7 , xvector= 1 0 1 0 1 1 0
8 ,     tmp= 0
8 , xvector= 1 0 1 0 1 1 0 0
```

 "1" "0" "1" "0" "1" "1" "0" "0" <== what I want is "unquoted" binary values

on the other hand, similar, NOT-THE-SAME but related, "conversions" are working, e.g.

```# seq = "1 0 0 1 0"
```

#> seq
```#  "1 0 0 1 0"
```

#> strsplit(paste(seq), " ")
```# []
#  "1" "0" "0" "1" "0"
```

#> paste(strsplit(paste(seq), " ")[], collapse="")
```#  "10010"
#
```

#> seq=c(0,0,0,1,1,0,1)
#> seq
```#  0 0 0 1 1 0 1
```

#> paste(strsplit(paste(seq), " "), collapse="")
#  "0001101"

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 09 Dec 2009 - 08:05:41 GMT

This archive was generated by hypermail 2.2.0 : Sat 12 Dec 2009 - 22:01:16 GMT