Learn R Programming

splitstackshape (version 1.0)

splitstackshape-package: splitstackshape

Description

Functions to split concatenated data, conveniently stack columns of data.frames, and conveniently reshape data.frames.

Arguments

Details

ll{ Package: splitstackshape Type: Package Version: 1.0 Date: 2013-08-12 License: GPL-3 }

Online data collection tools like Google Forms often export multiple-response questions with data concatenated in cells. The concat.split family of functions conveniently splits such data into separate cells. The package also includes functions to conveniently stack groups of columns and to reshape wide data, even when the data are "unbalanced"---something which reshape does not handle, and which melt and dcast from reshape2 do not easily handle.

Examples

Run this code
## concat.split
head(concat.split(concat.test, "Likes", drop = TRUE))

## Reshape
set.seed(1)
mydf <- data.frame(id_1 = 1:6, id_2 = c("A", "B"),
                   varA.1 = sample(letters, 6),
                   varA.2 = sample(letters, 6),
                   varA.3 = sample(letters, 6),
                   varB.2 = sample(10, 6),
                   varB.3 = sample(10, 6),
                   varC.3 = rnorm(6))
mydf
Reshape(mydf, id.vars = c("id_1", "id_2"),
        var.stubs = c("varA", "varB", "varC"))

## Stacked
Stacked(data = mydf, id.vars = c("id_1", "id_2"),
        var.stubs = c("varA", "varB", "varC"),
        sep = "\\.")

rm(mydf)

Run the code above in your browser using DataLab