View source: R/S03_Utilities.R
duplicate_wide_to_long | R Documentation |
Function to duplicate values in column x
from a wide-form (one row per case) data set wf
based on a shared column y
with a long-form
(multiple rows per case) data set lf
.
duplicate_wide_to_long(wf, lf, x, y, default = NA)
wf |
A wide-form data frame. |
lf |
A long-form data frame. |
x |
The column in |
y |
The column in both |
default |
The value to substitute if
no cases for |
A vector matching in length to the number
of rows of lf
with the values of x
repeated for each unique case of y
.
# Example wide-form data-frame
wf <- data.frame(
ID = 1:3,
Value = 4:6
)
# Example long-form data-frame
lf <- data.frame(
ID = rep( 1:3, each = 3),
Value = NA
)
# Duplicate values from 'wf' based
# on shared # column 'ID'
lf$Value <- duplicate_wide_to_long( wf, lf, x = Value, y = ID )
print( lf )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.