0

I have a data frame with color, quality and price and I want to compare how the color changes perception of quality.
I need to get a table with the mean of the prices for every color and quality combination.
I am currently trying with aggregate but I can't seem to find the proper combination.

aggregate(price ~ color, list(Quality = D$quality), data=D, FUN=mean);

Input:
Quality | Color | Price Good | Red | 4500 Excellent | Green | 5000 Bad | Blue | 420 ...... Output: mean prices table
. Red . Blue . Green Excellent . 4520 . 4200 . 3500 Good . 3950 . 3722 . 3021 Bad . 1523 . 1232 . 900

Arkaitz Jimenez
  • 22,500
  • 11
  • 75
  • 105

1 Answers1

0

Yuo can try:

library(tidyverse)
mtcars %>% 
  group_by(cyl, gear) %>% 
  summarise(M_mpg=mean(mpg)) %>% 
  spread(cyl, M_mpg)
Roman
  • 17,008
  • 3
  • 36
  • 49