Learn R Programming

DescTools (version 0.99.56)

SplitToCol: Split Data Frame String Column Into Multiple Columns

Description

Splitting the string columns of a data frame into multiple columns requires a considerable number of codelines, which are condensed in this function for convenience.

Usage

SplitToCol(x, split = " ", fixed = TRUE, na.form = "", colnames = NULL)

Value

A data.frame with all the columns splitted

A vector with the length of the number of columns of the data.frame containing the number of the found columns is returned as attribute namede "ncols".

Arguments

x

a data frame containing the string columns to be splitted.

split

character vector (or object which can be coerced to such) containing regular expression(s) (unless fixed = TRUE) to use for splitting. If empty matches occur, in particular if split has length 0, x is split into single characters. If split has length greater than 1, it is re-cycled along x.

fixed

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

na.form

character, string specifying how NAs should be specially formatted. Default is a blank "".

colnames

columnnames for the resulting data.frame. Will be recycled. Can easily be set to "" if no columnnames should be set.

Author

Andri Signorell <andri@signorell.net>

See Also

Examples

Run this code
d.frm <- data.frame(res1=c("2 [-3,5] **", "5 [-2,6] ***", "9 [-3,1]"),
                    res2=c("5 [6,8] **", "7 [-2,9]", "4 [3,5] **"), 
                    stringsAsFactors=FALSE)

SplitToCol(d.frm, na.form="-", colnames=c("coef", "ci", "pval"))

Run the code above in your browser using DataLab