do (version 1.4.0.0)

reshape_towide: Reshape to Wide Format

Description

Reshape to Wide Format

Usage

reshape_towide(data, id, col_change, prefix, suffix, sep = "_")

Arguments

data

long data

id

column names for id, which can be one or more

col_change

column names for exchange, which can be one or more

prefix

column names for prefix, which can be one or more

suffix

column names for suffix, which can be one or more

sep

seperation

Value

A wide data.

Examples

Run this code
# NOT RUN {
df = data.frame(id = c(1,1,2,2,3,3,4,4),
                time = c(1,2,1,2,1,2,1,2),
                w = c(1,6,2,7,3,8,4,9))

reshape_towide(data = df,
               id = 'id',
               col_change = 'time',
               prefix = 'w')
df = data.frame(id = c(1,1,2,2,3,3,4,4),
         time = c(1,2,1,2,1,2,1,2),
         w = c(1,6,2,7,3,8,4,9),
         h = c(5,1,6,3,7,5,8,7),
         n = c(2,2,3,3,4,4,5,5))

reshape_towide(data = df,
               id = 'id',
               col_change = c('time','n'),
               prefix  = 'w',sep = '_')

reshape_towide(data = df,
               id = 'id',
               col_change = 'time',
               prefix  = c('w','h'))

reshape_towide(data = df,
               id = c('id','n'),
               col_change = 'time',
               prefix  = c('w','h'))

df = data.frame(id = c(1,1,2,2,3,3,4,4),
                time = c('a','a','a','b','b','b','c','c'),
                n=c(5,5,6,6,7,7,8,8))
reshape_towide(data = df,id = 'id',col_change = 'time')
reshape_towide(data = df,id = c('id','time'),col_change = 'n')
reshape_towide(data = df,id = 'id',col_change = c('time','n'))
# }

Run the code above in your browser using DataLab