-1

I'm using R and have a dataframe with columns:

user_id brand_id gender ...

I want to create a new dataframe with each user_id appearing only once and with colums:

#brand1-#occurences #brand2-#occurrences ... male female ...

So I then could use the normal clustering methods.

Does anyone know how to do this?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
oyster
  • 11
  • 1
  • Do you want to [reshape data from long to wide in R](https://stackoverflow.com/questions/5890584/how-to-reshape-data-from-long-to-wide-format)? – Rui Barradas Jun 04 '21 at 17:13
  • 1
    Welcome! It is difficult to start generating ideas just from what you have provided. Please provide us with a small, reproducible code snippet that we can copy and paste to better understand the issue and test possible solutions. You can share datasets with `dput(YOUR_DATASET)` or smaller samples with `dput(head(YOUR_DATASET))`. (See [this answer](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#5963610) for detailed instructions.) – ktiu Jun 04 '21 at 17:36

1 Answers1

0

I believe, you want to reshape you data frame. Make two columns (female, male) from the one column (gender). The "array_reshape"-function from the reticulate package might help you.

wiebke
  • 111
  • 2