Skip to content

Instantly share code, notes, and snippets.

@martinctc
Created July 13, 2021 10:07
Show Gist options
  • Save martinctc/939de3aba673bf54c6b1fc3e019b4a14 to your computer and use it in GitHub Desktop.
Save martinctc/939de3aba673bf54c6b1fc3e019b4a14 to your computer and use it in GitHub Desktop.
[Duplicate rows in data frame based on n] #R
# 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