beg2char: Grab Begin/End of String to Character

Description Usage Arguments Value Author(s) References Examples

View source: R/beg2char.R

Description

beg2char - Grab from beginning of string to a character(s).

char2end - Grab from character(s) to end of string.

Usage

1
2
3
beg2char(text.var, char = " ", noc = 1, include = FALSE)

char2end(text.var, char = " ", noc = 1, include = FALSE)

Arguments

text.var,

A character string

char

The character from which to grab until/from.

noc

Number of times the character appears before the grab.

include

logical. If TRUE includes the character in the grab.

Value

returns a vector of text with char on/forward removed.

Author(s)

Josh O'Brien, Justin Haynes and Tyler Rinker <[email protected]>.

References

http://stackoverflow.com/q/15909626/1000343

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
x <- c("a_b_c_d", "1_2_3_4", "<_?_._:")
beg2char(x, "_")
beg2char(x, "_", 2)
beg2char(x, "_", 3)
beg2char(x, "_", 4)
beg2char(x, "_", 3, include=TRUE)

char2end(x, "_")
char2end(x, "_", 2)
char2end(x, "_", 3)
char2end(x, "_", 4)
char2end(x, "_", 3, include=TRUE)

x2 <- gsub("_", " ", x)
char2end(x2, " ", 2)
beg2char(x2, " ", 2)

x3 <- gsub("_", "\\^", x)
char2end(x3, "^", 2)
beg2char(x3, "^", 2)

## End(Not run)

Example output

Loading required package: qdapDictionaries
Loading required package: qdapRegex
Loading required package: qdapTools
Loading required package: RColorBrewer
OpenJDK 64-Bit Server VM warning: Can't detect initial thread stack location - find_vma failed

Attaching package: 'qdap'

The following object is masked from 'package:base':

    Filter

[1] "a" "1" "<"
[1] "a_b" "1_2" "<_?"
[1] "a_b_c" "1_2_3" "<_?_."
[1] "a_b_c_d" "1_2_3_4" "<_?_._:"
[1] "a_b_c_" "1_2_3_" "<_?_._"
[1] "b_c_d" "2_3_4" "?_._:"
[1] "c_d" "3_4" "._:"
[1] "d" "4" ":"
[1] "a_b_c_d" "1_2_3_4" "<_?_._:"
[1] "_d" "_4" "_:"
[1] "c d" "3 4" ". :"
[1] "a b" "1 2" "< ?"
[1] "c^d" "3^4" ".^:"
[1] "a^b" "1^2" "<^?"
Warning message:
system call failed: Cannot allocate memory 

qdap documentation built on Sept. 5, 2017, 9:04 a.m.