0

I have a dataset of pattern designers, there are 152 distinct designer names, each of them has a number of patterns (rows), each with a price. A total of 2403 objects.

I'd like to do a plot showing each designer's average price. The only ways I can think to do it is either create a new column for each unique designer name listing the average price of their specific items, or create a different data frame for each of the 152 designers, then calculate the average price from there. I'm hoping I don't have to do that much.

So how can I calculate each designer's average pattern price?

I was able to figure out there were 152 distinct designers using

> group_by_dn <- 
+     bags_2 %>%
+     group_by(designer_name) %>%
+     summarise()
> view(group_by_dn)

But I'm stuck on how to proceed from there.

"id";"designer_name";"pattern_name";"bag_type";"height_in_inches";"width_in_inches";"depth_in_inches";"currency";"exchange_rate";"price";"difficulty_level";"includes_svg_files";"video_tutorial_available";"link_to_pattern";"another_link";"victoria_owns"
"1";" Blue Calla";"Foxtail Cross Body Sling";"Crossbody";"13";"9.5";;"0.00";"0.00";"7.45";"Beginner";"Yes";"Yes";"https://bluecallapatterns.com/collections/sewing-patterns/products/foxtail-cross-body-sling-pdf-sewing-pattern";;NULL
"2";"Blue Calla";"Plumbago Organizer Pouch";"Pouch";"8.5";"7.75";"4";"0.00";"0.00";"9.32";"Intermediate";"Yes";"Yes";"https://bluecallapatterns.com/collections/sewing-patterns/products/plumbago-organizer-pouch-pdf-sewing-pattern";;NULL
"3";"Blue Calla";"Campanula Cross Body Phone Bag";"Crossbody";"5.375";"8.25";"2";"0.00";"0.00";"9.32";"Intermediate";"Yes";"Yes";"https://bluecallapatterns.com/collections/sewing-patterns/products/campanula-cross-body-phone-bag-pdf-sewing-pattern";;NULL
"4";"Blue Calla";"Winterberry Wallet";"Wallet";"7.375";"4.875";"1";"0.00";"0.00";"9.32";"Intermediate";"Yes";"Yes";"https://bluecallapatterns.com/collections/sewing-patterns/products/winterberry-wallet-pdf-sewing-pattern";;NULL
"5";"Blue Calla";"Bee Balm Waxed Canvas Backpack";"Backpack";"10.625";"12.25";"8.3";"0.00";"0.00";"9.32";"Intermediate";"No";"Yes";"https://bluecallapatterns.com/collections/sewing-patterns/products/bee-balm-waxed-canvas-backpack-pdf-sewing-pattern";;NULL
"6";"Blue Calla";"Coleus Bowler";"Bowler";"11.75";"10";"7";"0.00";"0.00";"9.32";"Intermediate";"No";"Yes";"https://bluecallapatterns.com/collections/sewing-patterns/products/coleus-bowler-bag-pdf-sewing-pattern";;NULL
"7";"Blue Calla";"Tumbleweed Toiletry Bag";"Toiletry";"12.75";"8.75";"6.375";"0.00";"0.00";"9.32";"Intermediate";"No";"Yes";"https://bluecallapatterns.com/collections/sewing-patterns/products/the-tumbleweed-toiletry-bag-pdf-sewing-pattern";;NULL
"8";"Blue Calla";"Lupin Laptop Bag";"Laptop";"16";"12";"3";"0.00";"0.00";"9.32";"Intermediate";"No";"Yes";"https://bluecallapatterns.com/collections/sewing-patterns/products/lupin-laptop-bag-pdf-sewing-pattern";;NULL
"9";"Blue Calla";"Larkspur Tote";"Tote";"14";"14";"5";"0.00";"0.00";"0.00";"Beginner";"No";"No";"https://bluecallapatterns.com/collections/sewing-patterns/products/free-the-larkspur-tote-bag-pdf-sewing-pattern";;NULL
"10";"Blue Calla";"Buttercup Bucket";"Bucket";"11.75";"12";"6";"0.00";"0.00";"9.32";"Intermediate";"No";"Yes";"https://bluecallapatterns.com/collections/sewing-patterns/products/buttercup-bucket-bag-pdf-sewing-pattern";;NULL
tuomastik
  • 4,559
  • 5
  • 36
  • 48
  • Basically you are on the right track. But you have to tell dplyr what you want to summarise, i.e. try with something like `summarise(avg_price = mean(price))` instead of just `summarise()`. If you need more help I would suggest to provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Nov 09 '22 at 21:57
  • thanks! but how do I tell it to do the average price by designer? – DivergentStitches Nov 09 '22 at 22:00
  • That's what the `group_by(designer_name)` is doing. – stefan Nov 09 '22 at 22:01
  • Ah I see! Ok I did that and got NA for every designer_name .. group_by_dn <- + bags_2 %>% + group_by(designer_name) %>% + summarise(avg_price = mean(price)) – DivergentStitches Nov 09 '22 at 22:04
  • 1
    aw. Sorry. Always forget about that. To remove any missing values when computing the mean do `summarise(avg_price = mean(price, na.rm = TRUE))` – stefan Nov 09 '22 at 22:15
  • I think the issue is that the prices are all decimals and it's trying to do an average which doesn't work .. I'm trying to figure out how to round up the prices now :) – DivergentStitches Nov 09 '22 at 22:23
  • I don't think so. From the data example you posted it's more likely your price column is a character instead of a numeric. To convert to a numeric try `summarise(avg_price = mean(as.numeric(price), na.rm = TRUE))`. – stefan Nov 09 '22 at 22:29

0 Answers0