jeudi 21 février 2019

R: Draw 100 random prices from each cut quality in diamonds data set?

I am using the diamonds data set:

install.packages("ggplot2")
library(ggplot2)
data("diamonds")

and I have to make a data frame that randomly takes 100 prices from each cut quality (Fair, Good, Very Good, Premium, Ideal) which would give me 500 data points. I'm having some trouble getting there and any help would be greatly appreciated! Here's a formula I tried but I can't seem to be able to figure out how to include all of the subsets that fall under 'cut'.

diamonds$price[ sample( diamonds$cut, size=100, replace=FALSE )]

I also tried using the aggregate function but that seemed to bring me even further away from where I was supposed to go. I'm sure I'm just missing something fairly obvious but I'm very new to this and I can't find anything about it online. Thank you!




Aucun commentaire:

Enregistrer un commentaire