Creating a vector of 2000 entries with 50 entries of 1, 50 entries of two.. up to 50 entries of 40

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.

Thank you in advance

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

Created on 2022-11-03 with reprex v2.0.2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.