Skip to contents

The purpose of this function is combine the functionality of strsplit, unlist and as.logical, which are often used together.

Usage

strsplit.bool(
  x,
  split,
  fixed = FALSE,
  perl = FALSE,
  useBytes = FALSE,
  type = 2
)

Arguments

x

character vector, each element of which is to be split. Other inputs, including a factor, will give an error.

split

character vector

fixed

logical. If TRUE match split exactly, otherwise use regular expressions. Has priority over perl.

perl

logical. Should Perl-compatible regexps be used?

useBytes

logical. If TRUE the matching is done byte-by-byte rather than character-by-character, and inputs with marked encodings are not converted.

type

type of return, see the as.boolean function for more info

Value

boolean values based on split string

Details

Given a sting, split by a separator into boolean

Examples

# string of numbers
num.01 = "0 1 0 0 1 0 1 T F TRUE FALSE t f"

# split a string of numbers and return as boolean 1/0
strsplit.bool(num.01, split = " ", type = 3)
#>  [1] 0 1 0 0 1 0 1 1 0 1 0 1 0
#> Levels: 0 1

# split a string of numbers and return as boolean TRUE/FALSE
strsplit.bool(num.01, split = " ", type = 2)
#>  [1] FALSE  TRUE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE  TRUE FALSE  TRUE
#> [13] FALSE

# split a string of numbers and return as boolean Yes/No
strsplit.bool(num.01, split = " ", type = 1)
#>  [1] No  Yes No  No  Yes No  Yes Yes No  Yes No  Yes No 
#> Levels: No Yes


# string of numbers
num.02 = "0abc1abc0abc0abc1abc0abc1abcTabcFabcTRUEabcFALSEabcf"

# split a string of numbers and return as boolean 1/0
strsplit.bool(num.02, split = "abc", type = 3)
#>  [1] 0 1 0 0 1 0 1 1 0 1 0 0
#> Levels: 0 1

# split a string of numbers and return as boolean TRUE/FALSE
strsplit.bool(num.02, split = "abc", type = 2)
#>  [1] FALSE  TRUE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE  TRUE FALSE FALSE

# split a string of numbers and return as boolean Yes/No
strsplit.bool(num.02, split = "abc", type = 1)
#>  [1] No  Yes No  No  Yes No  Yes Yes No  Yes No  No 
#> Levels: No Yes