Learn R Programming

taRifx (version 1.0.6.2)

expandDF: Functions to manipulate data frames

Description

expandDF takes a dataframe and replicates the chosen observations n times

Usage

expandDF(df, obs, numtimes = 1)

splitDF(df, splitvar)

unsplitDF(splitdfs)

Arguments

df

Data.frame to be manipulated

obs

Vector to select rows of df (e.g. vector of row numbers or a boolean of length nrow(df) )

numtimes

Number of times to replicate

splitvar

Name of variable which defines groups on which df will be split

splitdfs

List of data.frames to recombine (generally created by splitDF)

Value

expandDF and unsplitDF return a data.frame splitDF returns a list of data.frames

Details

splitDF takes a dataframe and splits it into a bunch of data.frames held in a list, according to one variable

unsplitDF takes a list of data.frames produced by splitDF and returns them as one appended data.frame

Examples

Run this code
# NOT RUN {
library(datasets)
# Duplicate a dataset
expandDF(sleep,TRUE)
# Expand the final observation
expandDF(sleep,nrow(sleep),numtimes=10)
# Split a data.frame by group
s.df <- splitDF(sleep,'group')
s.df
# Reconstitute original data.frame
unsplitDF(s.df)
# }

Run the code above in your browser using DataLab