Filtering data from a vector

3

I have a data frame that lists a series of customer evaluations for different products (each record is an evaluation / note). I need to do some boxplots with the evaluations of some specific products (the ids of those products are in a vector), but not all of the products. I'd like to know how I say in R: Just get the product ratings have the ids in that vector and mount a boxplot for each product. Can anyone help me?

Thank you!

    
asked by anonymous 29.10.2016 / 21:57

2 answers

1

I know the question has already been resolved but, as far as I understand, you needed to remove some products from your base before doing the boxplot. And the id of those products was saved in another vector. So follow a small complement.

Example:

excluir_produtos <- c(1,2,3)
base <- data.frame(
  produto = rep(1:5, each = 20),
  nota = runif(100)
)
base <- base[!base$produto %in% excluir_produtos,]

In this way, you exclude from the base all product lines 1, 2 and 3. Then you could do the graph, both the way that @Marcus posted it and using boxplot itself.

boxplot(nota ~ produto, base)

    
30.10.2016 / 02:33
2

One way to do this is with the ggplot2 package:

library(ggplot2)

data(mtcars)

ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) + geom_boxplot() +
labs(x="Cilindros", y="Milhas por Galão")

For this to be done, you must first join the vector with the product IDs and the data frame with the customer ratings.

    
29.10.2016 / 23:32