Abdul Basit Khan
Abdul Basit Khan

Reputation: 724

Repeat columns the number of times unique values in another column

I want to create a data.frame in R which has all the possible combinations of the following columns:-

  1. Items: length around 2000
  2. Weeks: length is 52 (Weeks in a Year)
  3. Place: factor of length 3 i.e. ("Top", "Center", "Bottom")
  4. Price: length around 2000 (each for each Item)

Upvotes: 0

Views: 146

Answers (1)

mharinga
mharinga

Reputation: 1780

Its not exactly clear to me what you would like to achieve. For example you can use expand.grid() to create a data.frame with all possible combinations:

items <- 1:200
weeks <- 1:52
place <- c("Top", "Center", "Bottom")
price <- 1:200

expand.grid(items, weeks, place, price)

Upvotes: 1

Related Questions