expanddf {mojson}R Documentation

Data Frame Expand

Description

Expand a data frame by splitting one column

Usage

expanddf(df, column, sep)

Arguments

df

data frame. The input to be expanded.

column

character. The column to be splitted.

sep

character. Separator for splitting a column.

Details

This function implements the data frame expansion if you need to split one column by the specific characters. The new data frame will generate the new columns named as 'level' appended by position-indexing numbers, such as 'level1', 'level2'. The maximum of appended numbers indicates the most splitting pieces for one cell. If the splitting results of one cell are fewer than the maximum, the row will be padded and corresponding cells will be filled with NAs.

Value

data frame. The resultant data frame with new columns.

Examples

library(mojson)
# levels are identical.
df1 <- data.frame(a = c('ab@gmail.com', 'cd@gmail.com'),
                  b = c(TRUE, FALSE))
expanddf(df1, 'a', '@')

# change the separator and treat various levels.
df2 <- data.frame(a = c('1-2-0', '1-2-0-3', '1-2'),
                  b = c(TRUE, FALSE, TRUE))
expanddf(df2, 'a', '-')


[Package mojson version 0.1 Index]