Learn R Programming

Kmisc (version 0.2.0)

kSplit: Split a Vector of Strings Following Regular Structure

Description

This function takes a vector of strings following a regular structure, and converts that vector into a data.frame, split on that delimiter. A nice wrapper to strsplit, essentially - the primary bonus is the automatic coersion to a data.frame.

Usage

kSplit(x, sep, names = NULL)

Arguments

x
a vector of strings
sep
the delimiter / regex you wish to split your strings on
names
optional: a vector of names to pass to the returned data.frame

See Also

strsplit

Examples

Run this code
dat <- kSplit(
  c("regular_structure", "in_my", "data_here"),
  sep="_",
  names=c("apple", "banana")
)
x <- c("somewhat_different.structure", "in_this.guy")
kSplit( x, "[_\\.]" )

Run the code above in your browser using DataLab