Learn R Programming

RAM (version 1.2.1.3)

col.splitup: Split Column Of Data Frame

Description

This function output consumes a data frame and split one by defined separator.

Usage

col.splitup(df, col="", sep="", max=NULL, names=NULL, drop=TRUE)

Arguments

df
a data frame.
col
name of a column in df.
sep
the separator to split the column. It can be regular expression.
max
optional. The number of columns to be split to.
names
optional. The names for the new columns.
drop
logical. Whether or not to keep the original column to be split in the output.

Value

The value returned by this function is a data frame. The selected column is split each separator and appended to the original data frame. The original column may may not to be kept in the output as defined by option drop.The number of columns to be split to depends on three factors, 1) the maximum columns that the original column can be split to by each separator; 2) the user definde max; and 3) the length of the column names defined by names. This function will split the column to the maximun number of the 3, empty columns will be filled with empty strings.

Examples

Run this code
data(ITS1)
# filter.OTU() returns a list
otu <- filter.OTU(list(ITS1=ITS1), percent=0.001)[[1]]
# split and keep taxonomy column
otu.split <- col.splitup(otu, col="taxonomy", sep="; ",
                          drop=FALSE)
## Not run: 
# # give new column names
# tax.classes <- c("kingdom", "phylum", "class",
#                   "order", "family", "genus")
# otu.split <- col.splitup(otu, col="taxonomy", sep="; ",
#                            drop=TRUE, names=tax.classes)
# ## End(Not run)

Run the code above in your browser using DataLab