StrChop: Split a String into a Number of Sections of Defined Length

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/DescTools.r

Description

Splitting a string into a number of sections of defined length is needed, when we want to split a table given as a number of lines without separator into columns. The cutting points can either be defined by the lengths of the sections or directly by position.

Usage

1
StrChop(x, len, pos)

Arguments

x

the string to be cut in pieces.

len

a vector with the lengths of the pieces.

pos

a vector of cutting positions. Will be ignored when len has been defined.

Details

If length is going over the end of the string the last part will be returned, so if the rest of the string is needed, it's possible to simply enter a big number as last partlength.

len and pos can't be defined simultaneously, only alternatively.

Typical usages are

1
2
StrChop(x, len)
StrChop(x, pos)

Value

a vector with the parts of the string.

Author(s)

Andri Signorell <[email protected]>

See Also

FixToTable, StrLeft, substr

Examples

1
2
3
4
5
6
7
8
x <- paste(letters, collapse="")
StrChop(x=x, len = c(3,5,2))

# and with the rest integrated
StrChop(x=x, len = c(3, 5, 2, nchar(x)))

# cutpoints at 5th and 10th position
StrChop(x=x, pos=c(5, 10))

DescTools documentation built on March 19, 2018, 9:03 a.m.