col_ungroup: col_ungroup: pull unique bits out of redudant column names to...

View source: R/col_ungroup.R

col_ungroupR Documentation

col_ungroup: pull unique bits out of redudant column names to make dataframe longer e.g. Contact1Phone Contac2Phone -> Phone grpvar

Description

col_ungroup: pull unique bits out of redudant column names to make dataframe longer e.g. Contact1Phone Contac2Phone -> Phone grpvar

Usage

col_ungroup(d, patt, grpvarcolname = "grpvar")

Arguments

d

is the dataframe with redudant columns

patt

is the pattern that matches redudant colnames (e.g. 'Contact[12]')

grpvarcolname

is name to give to the new column (def. 'grpvar')

Examples

   # as prefix
   d2   <- data.frame(x=1:3,Contact1Phone=4:6,Contact2Phone=7:9,Contact1Address=2:4)
   d2.ug<- col_ungroup(d2,'Contact[12]')
   # with suffix
   d1   <- data.frame(x=1:3,measure.a=4:6,measure.b=7:9,m2.a=2:4,m2.b=5:7)
   d1.ug<- col_ungroup(d1,'\\.(a|b)$')
   # watch out for patterns that match multiple parts of the same string
   # e.g. 'a|b' will be removed from 'measure.a' to make 'mesure'


LabNeuroCogDevel/LNCDR documentation built on July 13, 2024, 10:02 a.m.