So I created data on 2000 companies and now have to split them up into funds with 40 companies each. I'd like to do that by adding a new column to my data frame that consists of 1 for the first 50 rows, 2 for the next 50 rows and so on. Any ideas on how to solve this issue?
Maybe even "Fund #1" to "Fund #40" instead of just the numbers of 1 to 40.
Welcome to the community! Below is one approach that assigns each company to one of 40 different funds.
library(tidyverse)
df = data.frame(Company = paste0('Company ', 1:2000)) %>%
mutate(Fund = paste0('Fund #', sort(rep(1:40, 50))))
# first entry
head(df, 1)
#> Company Fund
#> 1 Company 1 Fund #1
# last entry
tail(df, 1)
#> Company Fund
#> 2000 Company 2000 Fund #40