Created
July 13, 2021 10:07
-
-
Save martinctc/939de3aba673bf54c6b1fc3e019b4a14 to your computer and use it in GitHub Desktop.
[Duplicate rows in data frame based on n] #R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# multiply values based on weights | |
wtest <- | |
data.frame( | |
x = c("cats", "dogs", "birds", "cats"), | |
y = c(1, 2, 3, 2) | |
) | |
wtest[rep(seq_len(nrow(wtest)), wtest$y),] | |
# https://stackoverflow.com/questions/11121385/repeat-rows-of-a-data-frame |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment